C Examples

WAP in C to read an array of 20 integers and print sum of all Entered no.’s!

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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X