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

相关文章:

  • 2021-07-07
  • 2021-09-11
猜你喜欢
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-02
相关资源
相似解决方案