C PROGRAMMING PROGRAM • DECISION MAKING
Calculate a Student Grade
Learn how to calculate a student grade using a clear C program.
PROBLEM UNDERSTANDING
Input and expected output
Sample input
86
Sample output
Grade B
COMPLETE C PROGRAM
Complete C implementation
#include <stdio.h>
int main(void)
{
double marks;
printf("Enter marks from 0 to 100: ");
scanf("%lf", &marks);
if (marks < 0 || marks > 100)
printf("Invalid marks\n");
else if (marks >= 90)
printf("Grade A\n");
else if (marks >= 80)
printf("Grade B\n");
else if (marks >= 70)
printf("Grade C\n");
else if (marks >= 60)
printf("Grade D\n");
else
printf("Grade F\n");
return 0;
}CURRENT STEP
SELECTED LINE
EXPECTED OUTPUT FOR THE SAMPLE
Grade B
Step 0 of 0
PROGRAM EXPLANATION
Algorithm and explanation
- Read the required input values.
- Validate the range and test grade boundaries from highest to lowest.
- Display the computed result.
Validate the range and test grade boundaries from highest to lowest.
EFFICIENCY
Time and space complexity
Time complexity
O(1)
Auxiliary space
O(1)
DEBUGGING CHECKLIST
Common mistakes
Check this
Use the correct format specifier for every variable.
Check this
Initialize variables before using their values.
Check this
Check braces, semicolons and input order carefully.
Try it yourself
Practice: Run the program with the sample input, predict its output, and then test one boundary case of your own.
