C Online Compiler
Example: C Program to Find Grade of a Student Using Function
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program to Find Grade of a Student Using Function #include <stdio.h> // @Custom function to Display Percentage & Grade void CalcPercentGrade(float subject_1, float subject_2, float subject_3, float subject_4, float subject_5) { float total, average, percentage; char grade; // 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 calculate the Grade if (average >= 90) grade = 'A'; else if (average >= 80 && average < 90) grade = 'B'; else if (average >= 70 && average < 80) grade = 'C'; else if (average >= 60 && average < 70) grade = 'D'; else grade = 'E'; // It will display final calculation 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); } // @Driver function to Run this Program int main() { float subject_1, subject_2, subject_3, subject_4, subject_5; 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 produce the final output CalcPercentGrade(subject_1, subject_2, subject_3, subject_4, subject_5); return 0; }
98 88 76 66 65
Output
Clear
ADVERTISEMENTS