c语言1+2+3+4+5_C程序来计算系列1+(1 + 2)+(1 + 2 + 3)+(1 + 2 + 3 + 4)+ ... +(1 + 2 + 3 + ... + n)...
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 termint 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:220Read 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
總結
以上是生活随笔為你收集整理的c语言1+2+3+4+5_C程序来计算系列1+(1 + 2)+(1 + 2 + 3)+(1 + 2 + 3 + 4)+ ... +(1 + 2 + 3 + ... + n)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP rewinddir()函数与示例
- 下一篇: java的parse方法_Java即时类