Jump to content
xisto Community
zitendr

Math Program arithmetical progression problem

Recommended Posts

I think you forgot to post the code! :P


This program is inmediate. The sum of an arithmetic serie, when you know the first and last term of a serie of n elements:

S=N*(a[1]+a[N])/2;

but you know that

a[N]=a[1]+(N-1)*d;

Doing arithmetics, then:

a[1]=S/N-(N-1)*d/2;

a[n]=S/N+(N-1)*d/2;

#include <stdio.h>int main(){	double d,s,a1,an;	long n;	printf("\nHow many terms? ");	scanf("%d",&n);	printf("\nSum of all terms? ");	scanf("%lf",&s);	printf("\nCommon difference? ");	scanf("%lf",&d);	a1=s/n-(n-1)*d/2;	an=s/n+(n-1)*d/2;	printf("\nFist term A[1]: %f\nLast term A[%d]: %f\n\nSerie:",a1,n,an);	for(long i=1;i<=n;i++){		printf("%f",a1+(i-1)*d);		if(i<n) printf(", ");		}}

Edited by DrK3055A (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.