[ create a new paste ] login | about

Link: http://codepad.org/E5OyTsrf    [ raw code | output | fork | 1 comment ]

yhl20001210 - C++, pasted on Nov 12:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//temp_0x00000001.cpp
//To verify the 13th on the mathematics (of science subjects) paper of the Exam of the Union of "Known Schools in Northern Anhui". - Quick programming
//DEBUGGING ON codepad

#include <iostream>
using namespace std;

int main() {
    int i=1, S=0, n[4]={1, 0, -1, 0};
    cout<<"#init: i="<<i<<", S= "<<S<<"\n";
    do {
         cout<<"#S="<<S<<"+"<<(n[i%4])<<"=";
        S+=n[i%4];
        cout<<S<<"\n";
        cout<<"#i="<<i<<"+1"<<"=";
        i++;
        cout<<i<<"\n";
    } while (!(i>5));
    cout<<"#Result: S="<<S<<"\n";
    return 0;
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
#init: i=1, S= 0
#S=0+0=0
#i=1+1=2
#S=0+-1=-1
#i=2+1=3
#S=-1+0=-1
#i=3+1=4
#S=-1+1=0
#i=4+1=5
#S=0+0=0
#i=5+1=6
#Result: S=0


Create a new paste based on this one


Comments:
posted by yhl20001210 on Nov 12
But I am only able to make the computer do it. How can I do it myself?
reply