C Program to Calculate Grade of Student
Advertisements
Calculate Grade of Student Program in C
Write a C program to calculate grade of student, If percentage > 85 print A grade, If percentage <85 print B grade, If percentage <75 print C grade, If percentage <50 print D grade, If percentage <30 print fail."
Algorithm to calculate grade
- First received marks of each subject.
- Calculate sum of all subjects marks.
- divide total marks by number of subject (percentage=total marks / number of subject).
- If percentage > 85 print A grade, If percentage < 85 && percentage >= 75 print B grade, If percentage < 75 && percentage >= 50 print C grade, If percentage > 30 && percentage <= 50 print D grade, If percentage <30 print fail
- Finally print percentage on screen.
Program to calculate grade of student
#include<stdio.h> #include<conio.h> void main() { int no, i; float marks[10], per=0, total=0; clrscr(); printf("Enter number of subject: "); scanf("%d",&no); printf("Enter marks of %d subject: ",no); for(i=0; i<no; i++) { scanf("%f",&marks[i]); } for(i=0; i<no; i++) { total=total+marks[i]; } per=total/no; printf("Percentage: %f % \n",per); if(per>85) { printf("A grade"); } else if(per<85 && per>=75) { printf("B grade"); } else if(per<75 && per>=50) { printf("C grade"); } else if(per<50 && per>=30) { printf("D grade"); } else { printf("Fail"); } getch(); }
Output
Enter number of subject: 5 Enter marks of 5 subject: 90 50 70 60 80 Percentage: 70.00 % B grade
Program to calculate grade of student
Program to calculate grade of student
#include<stdio.h> #include<conio.h> void main() { char grade; int no, i; float marks[10], per=0, total=0; clrscr(); printf("Enter number of subject: "); scanf("%d",&no); printf("Enter marks of %d subject: ",no); for(i=0; i<no; i++) { scanf("%f",&marks[i]); } for(i=0; i<no; i++) { total=total+marks[i]; } per=total/no; printf("Percentage: %f % \n",per); if(per>85) { grade='A'; } else if(per<85 && per>=75) { grade='B'; } else if(per<75 && per>=50) { grade='C'; } else if(per<50 && per>=30) { grade='D'; } else { grade='F'; } printf("You got: %c Grade",grade); getch(); }
Output
Enter number of subject: 5 Enter marks of 5 subject: 90 50 70 60 80 Percentage: 70.00 % You got: B grade
Google Advertisment