zitendr 0 Report post Posted July 10, 2006 Short program in c to calculate first term when sum of n terms and common difference d is given. Share this post Link to post Share on other sites
seec77 0 Report post Posted July 11, 2006 I think you forgot to post the code! Share this post Link to post Share on other sites
DrK3055A 0 Report post Posted October 21, 2006 (edited) I think you forgot to post the code! 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 thata[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 October 21, 2006 by DrK3055A (see edit history) Share this post Link to post Share on other sites