C Examples

WAP in C to input the marks of n students,count the number of students who have obtained a, b, c,d and f grades

The Program in C when the user input the marks of n students,count the number of students who have obtained a, b, c,d and f grades is given below:

#include <stdio.h>

int main() {
    int n, i;
    int a_count = 0, b_count = 0, c_count = 0, d_count = 0, f_count = 0;
    printf("Enter the number of students: ");
    scanf("%d", &n);

    for (i = 1; i <= n; i++) {
        int marks;
        printf("Enter the marks of student %d: ", i);
        scanf("%d", &marks);

        if (marks >= 90) {
            a_count++;
        } else if (marks >= 80) {
            b_count++;
        } else if (marks >= 70) {
            c_count++;
        } else if (marks >= 60) {
            d_count++;
        } else {
            f_count++;
        }
    }

    printf("Number of students who got grade A: %d\n", a_count);
    printf("Number of students who got grade B: %d\n", b_count);
    printf("Number of students who got grade C: %d\n", c_count);
    printf("Number of students who got grade D: %d\n", d_count);
    printf("Number of students who got grade F: %d\n", f_count);

    return 0;
}

Output:

Enter the number of students: 2
Enter the marks of student 1: 98
Enter the marks of student 2: 94
Number of students who got grade A: 2
Number of students who got grade B: 0
Number of students who got grade C: 0
Number of students who got grade D: 0
Number of students who got grade F: 0

Pro-Tips💡

This program prompts the user to enter the number of students, then uses a for loop to iterate through the students.

Inside the for loop, it reads the marks of each student and uses if-else statements to check the range of the marks and increase the count of the corresponding grade.

After the loop, it prints the number of students who got each grade.

Note that the range of marks and the corresponding grades may vary depending on the grading system used by different educational institutes.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

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

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X