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 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;
}
                        

🖥 Program 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
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.