Program to calculate Grade of Student

Description

To calculate grade first calculate the percentage marks of student.
Now according to percentage, find grade of student.

C/C++

/* C Program to calculate Grade of Student */
//Save it as GradeStudent.c

#include<stdio.h>
int main(){

    int i, numSub;
    float marks[10], totalMark=0, percentageMarks;

    printf("Enter number of subjects : ");
    scanf("%d",&numSub);

    for(i=0;i<numSub;i++){
        printf("Enter mark of %d subject : ",(i+1));
        scanf("%f",&marks[i]);
        
        //Calculate total marks
        totalMark += marks[i];
    }

    //Calculate percentage of Marks
    percentageMarks = totalMark/numSub;

    printf("\nPercentage marks : %.2f %\n",percentageMarks);

    //Check grade
    if(percentageMarks >= 80){
        printf("Grade A");
    }else if(percentageMarks>=60 && percentageMarks < 80){
        printf("Grade B");
    }else if(percentageMarks>=40 && percentageMarks < 60){
        printf("Grade C");
    }else{
        printf("Fail");
    }

    return 0;
}
Input:
Enter number of subjects : 5
Enter mark of 1 subject : 65
Enter mark of 2 subject : 86
Enter mark of 3 subject : 52
Enter mark of 4 subject : 64
Enter mark of 5 subject : 76

Output:
Percentage marks : 68.6%
Grade B

Java

/* Java Program to calculate Grade of Student */
//Save it as GradeStudent.java

import java.io.*;
import java.util.Scanner;

public class GradeStudent {

    public static void main(String[] args) {

            Scanner scanner = new Scanner(System.in);
        
            int i, numSub;
        float totalMark=0, percentageMarks;
        
        float marks[] = new float[10]; 

        System.out.println("Enter number of subjects : ");
        numSub = scanner.nextInt();

        for(i=0;i<numSub;i++){
            System.out.println("Enter mark of "+(i+1)+" subject : ");
            marks[i] = scanner.nextFloat();
            
                //Calculate total marks
            totalMark += marks[i];
        }

            //Calculate percentage of Marks
        percentageMarks = totalMark/numSub;

        System.out.println("Percentage marks : "+percentageMarks+"%");
        
            //Check grade
        if(percentageMarks >= 80){
            System.out.println("Grade A");
        }else if(percentageMarks >= 60 && percentageMarks < 80){
            System.out.println("Grade B");
        }else if(percentageMarks <= 40 && percentageMarks > 60){
            System.out.println("Grade C");
        }else{
            System.out.println("Fail");
        }
    }
}
Input:
Enter number of subjects : 
5
Enter mark of 1 subject : 
65
Enter mark of 2 subject : 
86
Enter mark of 3 subject : 
52
Enter mark of 4 subject : 
64
Enter mark of 5 subject : 
76

Output:
Percentage marks : 68.6%
Grade B

Related Programs

1) Program to find simple interest
2) Program to calculate Gross Salary
3) Program to calculate Permutation And Combination
4) Program to display multiplication table of a number
5) Program to convert Octal to Decimal
6) Program to find HCF using Recursion
7) Simple Calculator Using If Else
8) Program to calculate Volume and Surface Area of Sphere
9) Program to find greatest of 3 numbers
10) Check whether a given number is a perfect number or not
Share Me

Leave a Reply