c语言1+2+3+4+5
The series is: 1+(1+2) +(1+2+3) +(1+2+3+4) + ... +(1+2+3+...+n), we have to find out the sum up to N terms.
该序列是: 1+(1 + 2)+(1 + 2 + 3)+(1 + 2 + 3 + 4)+ ... +(1 + 2 + 3 + ... + n) ,我们有找出N个项之和。
Solution:
解:
We know the sum of natural numbers up to n = (n(n-1))/2
我们知道n等于(n(n-1))/ 2的自然数之和
If we simplify this we get, n(n+1)(2n+4)/12
如果我们简化一下,我们得到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,
现在,让我们看一下使用using c程序对其进行编程,
#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
Read more...
...
C programs by categories
C程序分类
Sum of the series programs C
系列程序的总和C
Star/Asterisks Pattern programs in C
C中的星号/星号模式程序
翻译自: https://www.includehelp.com/c-programs/calculate-the-sum-of-the-series-1-1-2-1-2-3-1-2-3-4-1-2-3-n.aspx
c语言1+2+3+4+5