Write a c program to find grade of a student using switch statement
Class percentage
Distinction 85 to 100
First class 60 to 84
Second class 50 to 59
Pass class 35 to 49
#include<stdio.h>
#include<conio.h>
void main()
{
int m1,m2,m3,total,choice;
float per;
clrscr();
printf("Enter three subjects marks:\n");
scanf("%d%d%d",&m1,&m2,&m3);
total=m1+m2+m3;
per=total/3.0;
choice=(int)per/10;
printf("Total marks=%d\n",total);
printf("Percentage=%f\n",per);
printf("The result of the student=");
switch(choice)
{
case 10:
case 9:
case 8:printf("Distinction");
break;
case 7:
case 6:printf("First class");
break;
case 5:printf("Second class");
break;
case 4:printf("Pass class");
break;
case 3:
case 2:
case 1:printf("Fail");
}
getch();
}
Output:
run 1:
Enter three subjects marks:
33
30
32
Total marks=95
Percentage=31.666666
The result of the student=Fail
run 2:
Enter three subjects marks:
40
45
49
Total marks=134
Percentage=44.666668
The result of the student=Pass class
run 3:
Enter three subjects marks:
55
51
50
Total marks=156
Percentage=52.000000
The result of the student=Second class
run 4:
Enter three subjects marks:
66
65
70
Total marks=201
Percentage=67.000000
The result of the student=First class
run 5:
Enter three subjects marks:
89
88
80
Total marks=257
Percentage=85.666664
The result of the student=Distinction
No comments: