#include<stdio.h>
int main()
{
int n, sum = 0, c, array[100]; // Declaring the variables
printf("Enter the number of integers you want to add: ");
scanf("%d", &n); // Accepting the number of integers from user
printf("\n\nEnter %d integers \n\n", n);
for(c = 0; c < n; c++) // Loop to accept the n numbers from user
{
scanf("%d", &array[c]); // Accepts the numbers from user and stores in an array
sum += array[c]; // Sums the numbers and stores in a variable named 'sum'
}
printf("\n\nSum = %d\n\n", sum); // Prints the sum of the entered integers
printf("\n\n\t\t\tCoding is Fun !\n\n\n");
return 0;
}
- In the above code block, we have added comments to describe each step of the program to help make it more readable.
Full Code:
#include<stdio.h>
int main()
{
int n, sum = 0, c, array[100]; // Declaring the variables
printf("Enter the number of integers you want to add: ");
scanf("%d", &n); // Accepting the number of integers from user
printf("\n\nEnter %d integers \n\n", n);
for(c = 0; c < n; c++) // Loop to accept the n numbers from user
{
scanf("%d", &array[c]); // Accepts the numbers from user and stores in an array
sum += array[c]; // Sums the numbers and stores in a variable named 'sum'
}
printf("\n\nSum = %d\n\n", sum); // Prints the sum of the entered integers
printf("\n\n\t\t\tCoding is Fun !\n\n\n");
return 0;
}