{ float sum, n, a, d, l;//n=no of term, a=first term, d=different, l=last term
d=1, a=1, l=100, n=l-a+1;
sum=(n/2)*(2*a+(n-1)*d);
printf("The sum of the numbers from %f to %f is %f.", a, l, sum);
#include <stdio.h>
int main()
{ float sum, n, a, d, l;
n=l-a+1, d=1, a=1, l=100;
sum=(n/2)*(2*a+(n-1)*d);
printf("The sum of the numbers from %f to %f is %f.", a, l, sum);
fflush(stdin);
printf("\n\nPlease press Enter to continue......");
getchar ();
return 0;
}
Leave a comment: