Grade Sheet Generator:
C
Easy
2 views
Problem Description
Input marks for 5 subjects. If any mark is less than 0 or more than 100, input that subject again. Calculate the total and percentage only after all marks are valid.
Official Solution
#include <stdio.h>
int main() {
int i;
float marks[5], total = 0, percentage;
for (i = 0; i < 5; i++) {
while (1) {
printf("Enter marks for subject %d: ", i + 1);
scanf("%f", &marks[i]);
if (marks[i] >= 0 && marks[i] <= 100) {
break; // valid mark
} else {
printf("Invalid marks! Enter marks between 0 and 100.n");
}
}
total += marks[i];
}
percentage = total / 5;
printf("nTotal Marks = %.2f", total);
printf("nPercentage = %.2f%%n", percentage);
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!