Dremendo Tag Line

Input subject marks and check pass or fail in C

if else if - Question 9

In this question, we will see how to input marks of English, Math and Computer of a student and check whether he is pass in the examination or not in C programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.

Q9) Write a program in C to input marks of English, Math and Computer of a student and check whether he is pass in the examination or not. For passing in an examination one must get above 40 in at least two subjects or the average of the three subjects must be greater than 40.

Program

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

int main()
{
    int s1,s2,s3;
    float avg;
    printf("Enter marks obtained in 3 subjects\n");
    scanf("%d%d%d",&s1,&s2,&s3);
    avg=(s1+s2+s3)/3.0;
    if(s1>40 && s2>40)
    {
        printf("Pass");
    }
    else if(s2>40 && s3>40)
    {
        printf("Pass");
    }
    else if(s3>40 && s1>40)
    {
        printf("Pass");
    }
    else if(avg>40)
    {
        printf("Pass");
    }
    else
    {
        printf("Fail");
    }
    return 0;
}

Output

Enter marks obtained in 3 subjects
56
34
45
Pass
video-poster