First Encounter with ACM — Faith in Chinese

Words: 76

To explore how the for loop works

I needed to write a program that computes the sum of the first n terms

After finishing the basic version

I went ahead and wrote this monstrosity…

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include<stdio.h>
//求前n项和 
int main()
{int shouxiang,qianjixiang,he;
shouxiang=1; 
he=0;
for (qianjixiang=1;qianjixiang<=3;qianjixiang++)
    {he=shouxiang+he;
    shouxiang=shouxiang*2; } 
    printf("%d",he);
 } 

-.- Code with absolutely no problems at all

Though this intense resentment seems utterly meaningless…

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...