Write a C program to convert the obtained marks into percentage
Description: Take the obtained marks and the total marks as input. Print the percentage.
Hint:
- Percentage = (obtained marks / total marks) x 100.
C program to calculate the percentage
#include <stdio.h>
int main(void) {
float obtained, total, percentage;
printf("Enter obtained marks and total marks: ");
scanf("%f %f", &obtained, &total);
percentage = obtained / total * 100;
printf("Percentage = %.2f%%\n", percentage);
return 0;
}
Output:
Output of the above program is
Enter obtained marks and total marks: 432 500
Percentage = 86.40%
How it works
432 / 500 * 100is 86.4.- To print the percent sign with
printf()we write%%.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |