Advertisement
Guest User

stop calculation when input is -1

a guest
Jun 17th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.18 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int x=0,sum=0;
  5.     while(x!=(-1))
  6.     {
  7.  
  8.         sum+=x;
  9.         scanf("%d",&x);
  10.     }
  11.     printf("sum = %d\n",sum);
  12.     return 0;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement