编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值

编写一个程序,求s=1+(1+2)+(1+2+3)+…+(1+2+3+…+n)的值

  1 #import <Foundation/Foundation.h>

 2 
 3 int main(int argc, const char * argv[]) {
 4     @autoreleasepool {
 5         int shu=0,he=0;
 6         for (int i=1; i<=100; i++) {
 7             shu+=i;
 8             he+=shu;
 9             //printf("he is:%d ",he);
10         }
11         printf("he is:%d ",he);
12         return 0;
13     }
14 }

执行结果: 

为了更好点交流和学习,请大家在参阅博客后,留下你的疑问和宝贵意见。谢谢!!!!
原文地址:https://www.cnblogs.com/fshmjl/p/4546333.html