C PROGRAMMING PROGRAM • DECISION MAKING

Calculate a Student Grade

Learn how to calculate a student grade using a clear C program.

BeginnerRange checkselse-if ladderGrades

PROBLEM UNDERSTANDING

Input and expected output

Sample input
86
Sample output
Grade B

COMPLETE C PROGRAM

Complete C implementation

student-grade-calculator.c
Open in compiler
#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;
}

GUIDED CODE TOUR • NOT LIVE EXECUTION

Study the program line by line

Use the real compiler button above to run and debug with different inputs.

CURRENT STEP

Select Start to walk through the important lines.

SELECTED LINE

No line selected

EXPECTED OUTPUT FOR THE SAMPLE

Grade B
0%Step 0 of 0

PROGRAM EXPLANATION

Algorithm and explanation

  1. Read the required input values.
  2. Validate the range and test grade boundaries from highest to lowest.
  3. 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.