The Program in C to read an array of 20 integers and print sum of all Entered no.’s is given below:
#include <stdio.h>
int main() {
int n, sum = 0;
for (int i = 0; i < 20; i++) {
printf("Enter a number: ");
scanf("%d", &n);
sum += n;
}
printf("Sum of all entered numbers: %d", sum);
return 0;
}
Output:
Enter a number: 23
Enter a number: 45
Enter a number: 66
Enter a number: 77
Enter a number: 4
Enter a number: 3
Enter a number: 55
Enter a number: 6
Enter a number: 99
Enter a number: 87
Enter a number: 55
Enter a number: 44
Enter a number: 356
Enter a number: 79
Enter a number: 35
Enter a number: 32
Enter a number: 34
Enter a number: 56
Enter a number: 45
Enter a number: 33
Sum of all entered numbers: 1234
Pro-Tips💡
This program uses a for loop to repeatedly prompt the user to enter a number, using the printf
function.
The scanf
function is used to read the user’s input and store it in the n
variable.
The sum
variable is initialized to 0 and is incremented by the value of n
in each iteration of the loop.
Finally, the program uses the printf
function to print the sum of all the entered numbers.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.