Given below is a c program to check student result using if else condition.
Condition for declaring a student as pass or fail is given below:
- For, percentage >= 40 : Pass
- For, percentage < 40 : Fail
C program to check whether a student is pass or fail:
Output:
Problem: Write a program to find grade of a student given his marks using switch
Solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#include<stdio.h> int main() { int i; float mark, sum=0, avg; printf("Enter Marks obtained in 5 Subjects: "); for(i=0; i<5; i++) { scanf("%f", &mark); sum = sum+mark; } avg = sum/5; printf("\nGrade = "); int score = avg / 10; switch(score){ case 10: case 9: printf("A1"); break; case 8: printf("A2"); break; case 7: printf("B1"); break; case 6: printf("B2"); break; case 5: printf("C1"); break; case 4: printf("C2"); break; case 3: printf("D"); break; case 2: printf("E1"); break; case 1: case 0: printf("E2"); break; default: printf("Invalid!"); break; } return 0; } |