Programming Example
Write a program in C that prints the grade according to the score secured by a student
Write a program in C that prints the grade according to the score secured by a student
#include <stdio.h>
int main()
{
int score;
char grade;
printf("\n ENTER SCORE : ");
scanf("%d", &score);
if(score >= 90)
grade = 'A';
else if(score >= 80)
grade = 'B';
else if(score >= 70)
grade = 'C';
else if(score >= 60)
grade = 'D';
else
grade = 'F';
printf("GRADE IS: %c", grade);
getch();
return 0;
}
<b>Output 1:</b>
ENTER SCORE : 82
GRADE IS: B
<b>Output 2:</b>
ENTER SCORE : 96
GRADE IS: A
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.