首页 > 其他 > 详细

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

时间:2015-06-02 14:57:06      阅读:708      评论:0      收藏:0      [点我收藏+]

编写一个程序,求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 }

 

执行结果: 技术分享

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

原文:http://www.cnblogs.com/fshmjl/p/4546333.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!