Student Grade Calculator Program in C

C language में एक ऐसा program लिखिए जो user से चार subjects के marks input ले:

  • Science
  • Math
  • English
  • Computer

और फिर:

  1. Total marks
  2. Percentage
  3. Grade (A, B, C, D या Fail)

calculate करके display करे।

Program Code

#include<stdio.h>

int main()
{
    float science, math, english, computer;
    float total, percentage;

    printf("Enter marks of Science : ");
    scanf("%f", &science);

    printf("Enter marks of Math : ");
    scanf("%f", &math);

    printf("Enter marks of English : ");
    scanf("%f", &english);

    printf("Enter marks of Computer : ");
    scanf("%f", &computer);

    total = science + math + english + computer;
    percentage = (total / 400) * 100;

    printf("\nTotal Marks : %.2f", total);
    printf("\nPercentage : %.2f", percentage);

    if (percentage >= 90)
        printf("\nGrade A");
    else if (percentage >= 75)
        printf("\nGrade B");
    else if (percentage >= 60)
        printf("\nGrade C");
    else if (percentage >= 40)
        printf("\nGrade D");
    else
        printf("\nTry Next year");

    return 0;
}

 Program Explanation

यह program real-life marksheet logic पर based है, इसलिए ये program beginners के लिये useful होगा।

1️. Variables का use

float science, math, english, computer;

यह variables चार subjects के marks store करने के लिए हैं।
float इसलिए use किया गया है ताकि decimal marks भी handle हो सकें (जैसे 78.5)।

float total, percentage;

  • total → चारों subjects का Marks store करने के लिये
  • percentage → Total Percentage Store करने के लिये

2️. Marks Input

scanf(“%f”, &science);

User से one-by-one हर subject के marks Input करने के लिये।

3️. Total और Percentage Calculation

total = science + math + english + computer;

percentage = (total / 400) * 100;

  • Maximum marks = 400 (4 subjects × 100)
  • Percentage निकालने का formula:

    (Obtained Marks / Total Marks) × 100

4️. Output Formatting

printf(“\nTotal Marks : %.2f”, total);

%.2f का use करके output को 2 decimal places तक limit किया गया है, जो professional दिखता है।

5️. Grade Logic (Important Part)

if (percentage >= 90)

यहाँ if–else ladder का use हुआ है:

PercentageGrade
90+A
75–89B
60–74C
40–59D
Below 40Fail

Program top से bottom check करता है और first true condition पर रुक जाता है।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top