008.数列求和

简介: 008.数列求和
#include <stdio.h>
main()
{
  int i,j,n;
  long sum=0,temp=0;
  printf("Please input a number to n:\n");
  scanf("%d",&n);
  if(n<1)
  {
    printf("The n must no less than 1!\n");
    return;
  }
  for(i=1;i<=n;i++)
  {
    temp=0;
    for(j=1;j<=i;j++)
      temp+=j;
    sum+=temp;
  }
  printf("The sum of the sequence(%d) is %d\n",n,sum);
  getchar();
  getchar();
}
目录
打赏
0
0
0
0
1
分享
相关文章
|
7月前
|
累加求和 1~ n求和
累加求和 1~ n求和
114 4
|
8月前
|
C++
643. 子数组最大平均数 I(C++)
643. 子数组最大平均数 I(C++)
|
9月前
【P1035】级数求和
【P1035】级数求和
|
8月前
1685. 有序数组中差绝对值之和
1685. 有序数组中差绝对值之和
|
10月前
27.数列1,2,2,3,3,3,4,4,4,4,5,……
27.数列1,2,2,3,3,3,4,4,4,4,5,……
65 0
|
10月前
|
643.子数组最大平均数
643.子数组最大平均数
38 0
迭代法解决递推问题:数列和,sinx,ex的近似值
迭代法解决递推问题:数列和,sinx,ex的近似值
147 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等