C programming to find out the average of 4 integers

C Programming Language / Array in C Language

13954

Program:

 /*
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

This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.