merkator

1068

Oct 2nd, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include<cstdio>
  2.  
  3. // for abs function
  4. #include<algorithm>
  5.  
  6. int main(){
  7.     int a, b, sum = 0;
  8.     scanf("%d", &a);
  9.     b=abs(a);
  10.     if (a>0) {
  11.         for (int i=1; i<=a; i++){
  12.         sum += i;
  13.         }
  14.     }
  15.     if (a<0){
  16.     for (int i=1; i<=b; i++){
  17.         sum += i;
  18.         sum == 1 - sum;
  19.     }
  20.     }
  21.     printf("%d", sum);
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment