Home / Programs / C programming to find out the average of 4 integers
Programming Example

C programming to find out the average of 4 integers

👁 12,293 Views
💻 Practical Program
📘 Step by Step Learning
C programming to find out the average of 4 integers

Program Code

 /*
C programming to find out the average of 4 integers  
 Author: atnyla Developer
 */


#include <stdio.h>
int main()
{
    int avg = 0;
    int sum =0;
    int x=0;

    /* Array- declaration – length 4*/
    int num[4];

    /* We are using a for loop to traverse through the array
     * while storing the entered values in the array
     */
    for (x=0; x<4;x++)
    {
        printf("Enter number %d \n", (x+1));
        scanf("%d", &num[x]);
    }
    for (x=0; x<4;x++)
    {
        sum = sum+num[x];
    }

    avg = sum/4;
    printf("Average of entered number is: %d\n", avg);
    return 0;
}

Output

Enter number 1
10
Enter number 2
20
Enter number 3
30
Enter number 4
40
Average of entered number is: 25 

Explanation

C programming to find out the average of 4 integers

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.