Tuesday, July 04, 2006

[2/3] Calculation of Marks using else if

This program is the same one done previously. The only difference that it is done using logical operators. Better over the if else type and removes the problem of mismatching between if-elses.

The marks obtained by a student in 5 different subjects are input through the keyboard.
The student gets a division as per the following rules:

Percentage above or equal to 60 - First Division
Percentage between 50 and 59 -- Second Division
Percentage between 40 and 49 --- Third Division
Percentage less than 40 ---- Fail

Write a program to calculate the division obtained by the student.


int m1, m2, m3, m4, m5, per;

printf("Enter the marks obtained in five subjects:");
scanf ("%d %d %d %d %d ", &m1, &m2, &m3, &m4, &m5);

per = (m1+m2+m3+m4+m5)/5;

if (per>=60)
printf ("First Division");

else if (per>=50)
printf ("Second Division");

else if (per>=40)
printf ("Third Division");

printf ("Fail");

The file can be found at:
Download File

No comments: