Dremendo Tag Line

Calculate average and check good or bad in C

if else - Question 6

In this question, we will see how to input 5 decimal numbers and print good if their average is greater than 50, otherwise print bad in C programming using the if else statement. To know more about if else statement click on the if else statement lesson.

Q6) Write a program in C to input 5 decimal numbers and find their average. If the average is greater than 50 then print Good, otherwise print Bad.

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    float a,b,c,d,e,avg;
    printf("Enter 5 decimal numbers\n");
    scanf("%f%f%f%f%f",&a,&b,&c,&d,&e);
    avg=(a+b+c+d+e)/5;
    printf("Average=%f\n",avg);
    if(avg>50)
    {
        printf("Good");
    }
    else
    {
        printf("Bad");
    }
    return 0;
}

Output

Enter 5 decimal numbers
86.23
75.18
92.10
69.35
78.14
Average=80.199997
Good
video-poster