C program to find sum of n numbers is a very easy and simple program. Generally, such programs asked in the exam. This is the basic program in c.
Example:
Suppose we have the 4 numbers as 10, 20, 30, 40
Sum of N numbers will add all 4 numbers = 10 + 20 + 10 + 10
Sum of 4 numbers is = 50

Algorithm to find sum of n numbers

  1. Declare variables. N, sum, nos
  2. Take total numbers want to sum. N
  3. Take input N numbers
    For i=1 to N
    Input value
    sum = sum + value
  4. Print sum of N numbers. sum

C program to find sum of n numbers

#include <stdio.h>

int main()
{
int n, sum = 0, c, value;

printf("How many numbers you want to add?\n");
scanf("%d", &n);

printf("Enter %d integers\n", n);

for (c = 1; c <= n; c++)
{
scanf("%d", &value);
sum = sum + value;
}

printf("Sum of the integers = %d\n", sum);

return 0;
}

Output:

C program to find sum of n numbers

Write A Comment