We know the sum of natural numbers up to n = (n(n-1))/2
If we simplify this we get, n(n+1)(2n+4)/12
If we put the number of terms in the above equation then we'll get the sum of the series up to that particular term.
Now, let's see Program it using the using c program,
#include <stdio.h>
//function for creating the sum of the
//series up to Nth term
int series_sum(int n)
{
return ((n * (n + 1) * (2 * n + 4)) / 12);
}
int main()
{
int n;
printf("Series:1+(1+2+)+(1+2+3)+...+(1+2+3+...+n)\n");
printf("Want some up to N terms?\nEnter the N term:");
scanf("%d", &n);
printf("Sum is:%d", series_sum(n));
return 0;
}
Output
Series:1+(1+2+)+(1+2+3)+...+(1+2+3+...+n)
Want some up to N terms?
Enter the N term:10
Sum is:220
We know the sum of natural numbers up to n = (n(n-1))/2
If we simplify this we get, n(n+1)(2n+4)/12
If we put the number of terms in the above equation then we'll get the sum of the series up to that particular term.
Now, let's see Program it using the using c program,
Output
need an explanation for this answer? contact us directly to get an explanation for this answer