A program to explain IF ELSE IF ladder
C Programming Language 020
The following code shows how to write a program to explain IF ELSE IF ladder.
Program
/**
* Reade three subject marks of a student and find the average of the marks.
* Decide the student's grade by rules given below.
* 70 <= Average - Grade A
* 60 <= Average < 70 - Grade B
* 50 <= Average < 60 - Grade C
* 40 <= Average < 50 - Grade D
* Average < 40 - Fail
*/
#include <stdio.h>
void main()
{
int sub1, sub2, sub3;
float avg;
printf("Enter 3 subject marks:\n");
scanf("%d %d %d", &sub1, &sub2, &sub3);
avg = (sub1 + sub2 + sub3) / 3.0;
printf("Average = %f\n", avg);
if (avg >= 70)
printf("Grade A");
else if (avg < 70 && avg >= 60)
printf("Grade B");
else if (avg < 60 && avg >= 50)
printf("Grade C");
else if (avg < 50 && avg >= 40)
printf("Grade D");
else
printf("Fail");
printf("\n");
}
Result
Enter 3 subject marks:
100 70 90
Average = 86.666664
Grade A
Last Updated on
Comments