c program for student grade calculation

If else if ladder


If else if ladder can be used for a series of condition checks. The if and else if checks for a condition, if it matches, the statements associated with it will be executed. If none of these conditions matches then the statement associated with else will be executed.

Explanation of the program


This program uses if else if ladder for student grade calculation. The marks for three subjects is read as input and stores in the variables m1, m2 and m3 respectively. The average mark is calculated by the statement  g=(m1+m2+m3)/3. The value of g is checked in the if else if construct to print the corresponding grade. 

Program



#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

float m1,m2,m3,g;

printf("enter mark1");

scanf("%f",&m1);

printf("enter mark2");

scanf("%f",&m2);

printf("enter mark3");

scanf("%f",&m3);

g=(m1+m2+m3)/3;

if(g>=80)

printf("A grade");

else if(g>=60)

printf("B grade");

else if(g>=50)

printf("C grade");

else

printf("Failed");

getch();

}


Output



C program for student grade calculation using if else if construct.
C program for student grade calculation using if else if ladder


No comments: