|
|
back to boardDiscussion of Problem 1068. SumWhat's wrong? Posted by Fatum 13 Nov 2013 14:25 #include <iostream> using namespace std; int main(){
int a = 0; int b = 1; int c = 0; int k = 0;
cin >> a;
if(a > b){ k = 1;
for(; b <= a; b = b + k){
c += b;
}
}
else if(a < b){
k = -1;
for(; b >= a; b = b + k){
c += b;
}
}
cout << c; } |
|
|