Counting A and B Students Based on Grades
This C program prompts the user to enter grades for 10 students and counts how many received A (above 85) and B (above 75) grades. It ensures that the grades entered are between 0 and 100, requesting re-entry for invalid inputs. At the end, it displays the number of A and B students.#include <stdio.h> int main() { int i; int grade; int a_students = 0; int b_students = 0; for (i = 0; i < 10; i++) { printf("Please enter student %d grade: ", i+1); scanf("%d", &grade); if (grade <= 100 && grade >= 0) { if (grade > 85) { a_students++; } else { if (grade > 75) { b_students++; } } } else { printf(">> Please enter grade from 0 to 100\n"); i--; } } printf("A students = %d | B students = %d\n", a_students, b_students); return 0; }
Leave a Comment