# Calculate Sum of Maximum of 10 Numbers & Skip Negative Numbers

We will write a C program to calculate the sum of the maximum of 10 numbers and skip the negative numbers from the calculation.

To write this program we need to use a continue statement. The continue keyword in C doesn’t terminate the loop, but when the continue keyword occurs then control of the program jumped to the ending of the loop and later to the beginning of the loop. Due to this, the remaining statements of the loop after the continue keyword is skipped.

The program will take input multiple times from the user. So, we need to use the loops. In the below program we used for loop.

The for loop in C programming language is a pre-test loop, where first of all initialization expression is evaluated then the condition is checked and if the condition is true then only the statements of the for loop are executed.

## C program to calculate the sum (maximum 10 numbers) and skip negative numbers

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

for(int i=1 ; i<=10; i++)
{
// take input from the user
printf("Enter number: ");
scanf("%d",&number);

//-ve numbers are skipped
if( number<0 )
continue;

// calculate sum
sum += number; // sum = sum + number
}

// display result
printf("Sum = %d",sum);

return 0;
}``````

Output for different test-cases:-

Enter number: 15
Enter number: 1561
Enter number: 1
Enter number: 62
Enter number: -52
Enter number: -2
Enter number: 26
Enter number: -1000
Enter number: -65
Enter number: 100
Sum = 1765

Enter number: -56
Enter number: -50
Enter number: -512
Enter number: 10
Enter number: 54
Enter number: -900
Enter number: 5
Enter number: 32
Enter number: -2000
Enter number: 20
Sum = 121

In this program when the negative numbers are given from the number then the `if statement` becomes true and due to continue keyword the negative numbers are skipped from the calculations. Finally, we get the sum of only positive numbers.

Similar C program examples