Software & Finance





C Programming (Turbo C++ Compiler) - Simple Student Grading Logic





I have given here a simple student grading by using if conditions and pointer assignment.


Source Code


#include <stdio.h>

 

int main()

{

    int i, arrMark[10];

    char *grade = 0;

 

    for(i = 0; i < 10; i++)

    {

        printf("Enter %d Student Mark: ", i  + 1);

        scanf("%d", &arrMark[i]);

    }

 

    printf("\n\nNo\tMark\tGrade\n");

    for(i = 0; i < 10; i++)

    {

        if(arrMark[i] > 100)

            grade = "Error";

        else if(arrMark[i] > 90)

            grade = "A+";

        else if(arrMark[i] > 70)

            grade = "B+";

        else if(arrMark[i] > 50)

            grade = "C+";

        else if(arrMark[i] > 30)

            grade = "C";

        else

            grade = "F";

        printf("%d\t%d\t%s\n", i + 1, arrMark[i], grade);

    }

    return 0;

}

Output


Enter 1 Student Mark: 65

Enter 2 Student Mark: 76

Enter 3 Student Mark: 89

Enter 4 Student Mark: 95

Enter 5 Student Mark: 20

Enter 6 Student Mark: 45

Enter 7 Student Mark: 55

Enter 8 Student Mark: 67

Enter 9 Student Mark: 89

Enter 10 Student Mark: 29

 

 

No      Mark    Grade

1       65        C+

2       76      B+

3       89      B+

4       95      A+

5       20      F

6       45      C

7       55      C+

8       67      C+

9       89      B+

10      29      F

Press any key to continue . . .