58.2k views
1 vote
Write a program with a loop that asks the user to enter a series of positive numbers. the user should enter a negative number to signal the end of the series. after all the positive numbers have been entered, the program should display their sum.

User Chrona
by
8.2k points

1 Answer

2 votes
int main(void){
int n,s=0;
while(1){
scanf(" %d",&n);
if(n<0) break;
s+=n;
}
printf("sum=%d\\",s);
return 0;
}
User Rajat Mehra
by
8.1k points