Write a program to find out the average marks of five subjects given by the user. Also find out the results based of the average marks obtained by the student based on the following conditions

/*
Q.    Write a program to find out the average marks of five subjects given by the user. Also find out the results based of the average marks obtained by the student based on the following conditions                               
    a. “Fail” if mark of any subject is less than 30.
    b. “Simple Pass” if average marks is less than 45 but greater than or equal to 30
    c. “Second Division” if average marks is less than 65 but greater than or equal to 45
    d. “First Division” if average marks is greater than or equal to 65.
    e. “Invalid” if mark of any subject is less than 0 or greater than 100.

*/

#include<stdio.h>
main()
{
    float sub1,sub2,sub3,sub4,sub5,avg;
    printf("\nEnter marks of 5 subjects=");
    scanf("%d%d%d%d%d",&sub1,&sub2,&sub3,&sub4,&sub5);
    avg=(sub1+sub2+sub3+sub4+sub5)/5;
    if(sub1<0 || sub1>100 || sub2<0 || sub2>100 || sub3<0 || sub3>100 || sub4<0 || sub4>100 || sub5<0 || sub5>100)
        printf("Invalid");
    else if(sub1<30 ||sub2<30 ||sub3<30 ||sub4<30 ||sub5<30 )
        printf("Fail");
    else if(avg>=30 && avg<45)
        printf("Simple Pass");
    else if(avg>=45 && avg<60)
        printf("Second Division");
    else if(avg>=60)
        printf("First Division");
}

No comments:

Post a Comment