Calculate Sum of Maximum of 10 Numbers & Skip Negative Numbers

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest in 3 Numbers
Find Grade of student
Find the absolute value
Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of 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.

Learn more:- continue keyword in C

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

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest among 3 Numbers
Find Grade of student
Find the absolute value
Check Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

2 thoughts on “Calculate Sum of Maximum of 10 Numbers & Skip Negative Numbers”

Leave a Reply