Following is a program to find out Grace Marks using the switch :
Inputs
(1)Class Obtained and (2) No of the subjects, he has failed in
Use the following logic:
a. If the student gets first class and he fails in more than 3 subjects, he does not get
any grace. Otherwise, he gets a grace of 5 marks per subject.
b. If the student gets second class and he fails in more than 2 subjects, he does not
get any grace. Otherwise, he gets a grace of 4 marks per subject.
c. If the student gets third class and he fails in more than 1 subject, then he does
not get any grace. Otherwise, he gets a grace of 5 marks.
#include <stdio.h>
int main()
{
int class, sub, marks, grace;
printf("Enter the class: ");
scanf("%d", &class);
printf("Enter the number of failed subjects: ");
scanf("%d", &sub);
switch (class)
{
case 1:
if (sub > 3)
{
grace = 0;
}
else
{
grace = 5;
}
break;
case 2:
if (sub > 2)
{
grace = 0;
}
else
{
grace = 4;
}
break;
case 3:
if (sub > 1)
{
grace = 0;
}
else
{
grace = 5;
}
break;
default:
printf("Invalid Input");
break;
}
marks = sub * grace;
printf("The total grace marks given is %d", marks);
}