code:
#include<stdio.h> int main() { int number,sum=0; printf("Enter a positive number, negative to terminate:"); scanf("%d",&number); while(number>=0) { sum=sum+number; printf("Enter a positive number, negative to terminate:"); scanf("%d",&number); } printf("Sum is %d",sum); return 0; }
code output:
Enter a positive number, negative to terminate:7 Enter a positive number, negative to terminate:3 Enter a positive number, negative to terminate:4 Enter a positive number, negative to terminate:1 Enter a positive number, negative to terminate:-1 Sum is 15 Process returned 0 (0x0) execution time : 4.496 s Press any key to continue.