/* */ Click to Join Live Class with Shankar sir Call 9798158723
Q.) WAP to find out the average of 4 integers an array With C program.
    #include < stdio.h>
int main()
{
    int avg = 0;
    int sum =0;
    int x=0;

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

    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", avg);
    return 0;
}
Output

Enter number 1
10
Enter number 2
10
Enter number 3
20
Enter number 4
40

Average of entered number is: 20


Program Explanation


Step 1 : Include header files (#include< stdio.h> and #include< conio.h>).

Step 2 : Start with main function with return type.

Step 3 : parenthesis to start and end the program { }.

Step 4 : declare variables with data type i.e, 'avg = 0 , int sum =0 , x=0 , num[4]' is an integer type so we use "int" data type.

Step 5 : Use output function printf() to print the output on the screen.

Step 6 : Use input function scanf() to get input from the user.

Step 7 : here, find out the average of 4 integers an array , We are using a for loop to traverse through the array.while storing the entered values in the array , for loop was check the condition , if condition was true then excuted the loop otherwish not excute the loop , so condition was true the enter the loop and print on screen a 'Enter number' after you enter a number then 'scanf function' is used to seen the number. and then this number was go to another loop and then check the condition.the condition was true it will enter the loop and add a number and find the avg, by avg = sum/4,then print the result "Average of entered number is:" .

Step 8 : using getch() function to hold the screen.