C Program to Find Sum of N Numbers using For loop
ADVERTISEMENTS
C program to find sum of N numbers using for loop. In this article, You will learn how to make c program to find sum of N numbers using for loop.
Source Code
// C Program to Find Sum of N Numbers using For loop
#include <stdio.h>
int main() {
int s, i, sum = 0;
// s - To store the size of the array
printf("----Enter the size of the array----\n");
scanf("%d", &s);
int x[s];
// x - To store the array element to store the input numbers
printf("\n\n----The sum of the %d input numbers----\n\n", s);
for(i = 0; i < s; i++) {
scanf("%d", &x[i]);
sum += x[i];
}
printf("\n\nThe total sum is: %d", sum);
return 0;
}
Output
----Enter the size of the array----
6
----The sum of the 6 input numbers----
34
54
24
53
24
67
The total sum is: 256