系列2、6、12、20、30…的前N个项的总和。在C编程中
为了找到该系列的总和,我们将首先分析该系列。
该系列是:2,6,12,20,30…
示例
For n = 6 Sum = 112 On analysis, (1+1),(2+4),(3+9),(4+16)... (1+12), (2+22), (3+32), (4+42), can be divided into two series i.e. s1:1,2,3,4,5… andS2: 12,2,32,....
用数学公式求出第一和第二的总和
Sum1 = 1+2+3+4… , sum1 = n*(n+1)/2 Sum2 = 12+22+32+42… , sum1 = n*(n+1)*(2*n +1)/6
示例
#include <stdio.h>
int main() {
int n = 3;
int sum = ((n*(n+1))/2)+((n*(n+1)*(2*n+1))/6);
printf("the sum series till %d is %d", n,sum);
return 0;
}输出结果
The sum of series till 3 is 20
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下