Percentage is calculated by dividing the obtained total by the maximum possible total and multiplying by 100. Keep both values in floating-point form when a fractional percentage is possible.
#include <stdio.h>
int main(void) {
double obtained = 423.0;
double maximum = 500.0;
double percentage = obtained / maximum * 100.0;
printf("Percentage = %.2f%%\n", percentage);
return 0;
}
#include <stdio.h>
int main(void) {
double marks[5];
double total = 0.0;
printf("Enter marks for five subjects: ");
for (size_t i = 0; i < 5; i++) {
if (scanf("%lf", &marks[i]) != 1 ||
marks[i] < 0.0 ||
marks[i] > 100.0) {
printf("Each mark must be from 0 to 100.\n");
return 1;
}
total += marks[i];
}
double percentage = total / 5.0;
printf("Total = %.2f\n", total);
printf("Percentage = %.2f%%\n", percentage);
return 0;
}
if (percentage >= 80.0) {
printf("Grade A\n");
} else if (percentage >= 60.0) {
printf("Grade B\n");
} else if (percentage >= 40.0) {
printf("Grade C\n");
} else {
printf("Fail\n");
}
See the full grade program and division classification.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| Tahir khan | 09-11-2018 |
| i am a student. i want to become a software engineer this website is so helpful for me | |