Wednesday, August 5, 2026

Student Grade Classification || C Lab Programs

 Program 02: Student Grade Classification

Problem Statement:: Develop a C program that takes a student's marks as input and displays their grade based on specific criteria ranging from Grade A to Grade F. 

Problem Description:

  • Input: A single integer representing student marks (0 to 100).

  • Output: The corresponding grade (A, B, C, D, or F).

  • Constraints: Marks are assumed to be valid integers within the 0-100 range.

  • Method: Use an if-else ladder as the most efficient approach for range-based logic. 

Pgm Logic:

  1. Start.

  2. Input the student's marks.

  3. Use conditional statements to check:

    • If marks >= 90 Grade A.

    • Else if marks >= 75 Grade B.

    • Else if marks >= 60 Grade C.

    • Else if marks >= 50 Grade D.

    • Otherwise Grade F.

  4. Display the identified grade.

  5. Stop. 

Program Code:

// Purpose: To take student marks as input and display the corresponding grade using an if-else ladder.

#include <stdio.h>


void main()

{

    int marks;

    printf("Enter the student's marks (0 to 100): ");

    scanf("%d", &marks);

    if (marks < 0 || marks > 100)

        printf("Invalid marks! Please enter a value between 0 and 100.\n");

    else if (marks >= 90)

        printf("Grade: A\n");

    else if (marks >= 75)

        printf("Grade: B\n");

    else if (marks >= 60)

        printf("Grade: C\n");

    else if (marks >= 50)

        printf("Grade: D\n");

    else

        printf("Grade: F\n");

}


Output: Enter the student's marks (0 to 100): 95 Grade: A 

RESULT: Thus the program has been executed and the output was verified. 

Remarks: This program was successfully tested in the onlineGDB tool. Range-based selection makes the if-else ladder more suitable than a switch statement. 

Program Explanation: The program captures a numeric score and runs it through a series of thresholds. Once a condition is met, it prints the grade and skips the remaining checks.


For all 2026 published C Lab Program posts Index page: click here

For all 2026 published articles list:click here

…till the next post, bye-bye & take care


No comments:

Post a Comment