# Sum of Maximum of 10 Numbers Until User Enter Positive Numbers

We will write a C Program to calculate the sum of the maximum of 10 numbers and Calculate the sum until the user enter positive numbers.

The break, continue, goto, and return statements in C are Jump control statements. These statements cause the control to pass to any desired location in the program. There are several uses of break statement in C.

In this program, we need to use the break statement. When the break keyword is encountered inside the loop then immediately the loop is terminated and control resumes at the next statement following the loop.

The break statement has two uses.

It is used to terminate a case in the switch statement.
It is also used to force immediate termination of a loop, bypassing the normal loop conditional test.

The program will take input multiple times so, we need to use loops. In the below program, we use a while loop.

While loop in C is a pre-test loop where the expression is evaluated then only statements are executed. It uses a test expression to control the loop. Before every iteration of the loop, the test expression is evaluated.

## C program to calculate sum (maximum 10 numbers) until User enter positive numbers

``````#include<stdio.h>
int main()
{
int sum=0, number, i=1;

while(1) // condition always true
{

printf("Enter the number:");
scanf("%d",&number);

// If number is -ve then control
// came out from the while loop
if(number < 0)
break;

sum += number; // sum = sum + number
i++;

if( i>10 ) // maximum 10 numbers
break;

}

printf("Sum= %d", sum);

return 0;
}``````

Output:-

Enter the number: 10
Enter the number: 20
Enter the number: 25
Enter the number: 30
Enter the number: 50
Enter the number: 60
Enter the number: -50
Sum = 195

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or you find anything incorrect? Let us know in the comments. Thank you!

Similar C program examples