编写一个程序,求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\n",he);
10         }
11         printf("he is:%d\n",he);
12         return 0;
13     }
14 }

 

执行结果: 

posted @ 2015-06-02 14:10  fengsh_h  阅读(8751)  评论(0编辑  收藏  举报