C Online Compiler
Example: C Program to Find Grade of a Student Using Switch Case
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Find Grade of a Student Using Switch Case #include <stdio.h> int main() { float subject_1, subject_2, subject_3, subject_4, subject_5; float total, average, percentage; char grade; int sAvg; printf("Enter the marks of five subjects::\n"); scanf("%f%f%f%f%f", &subject_1, &subject_2, &subject_3, &subject_4, &subject_5); // It will calculate the Total, Average and Percentage total = subject_1 + subject_2 + subject_3 + subject_4 + subject_5; average = total / 5.0; percentage = (total / 500.0) * 100; // It will divides average by 10 check switch expression sAvg = (int) average / 10; // It will calculate the Grade switch (sAvg) { case 10: grade = 'A'; break; case 9: grade = 'A'; break; case 8: grade = 'B'; break; case 7: grade = 'C'; break; case 6: grade = 'D'; break; default: grade = 'E'; break; } // It will produce the final output printf("\nThe Total marks is: \t%.2f / 500.00\n", total); printf("\nThe Average marks is:\t%.2f\n", average); printf("\nThe Percentage is: \t%.2f%%\n", percentage); printf("\nThe Grade is: \t'%c'\n", grade); return 0; }
98 88 76 66 65
Output
Clear
ADVERTISEMENTS