Sum of n numbers in C: This program adds n numbers that a user inputs. The user enters a number indicating how many numbers to add and the n numbers. We can do it by using an array and without it.
#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:
How many numbers you want to add?
3
Enter 3 integers
1
2
3
Sum of the integers = 6
need an explanation for this answer? contact us directly to get an explanation for this answer