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 * 100 is 86.4.
  • To print the percent sign with printf() we write %%.

Learn more about the similar topics:
Tutorials
C Keywords
C Variables
C Data Types
C Constants
C printf and scanf
C Escape Sequences
C Format Specifiers
Exercises & Assignments
Write a C program to swap the values of two variables using a third variable
Write a C program to print words using spacing and new line characters
Write a C program to get the salary from the user and print it
Write a C program to find the size of int, float, long, double and char
Write a C program to get the marks of 5 subjects and find the total and average
Write a C program to calculate the perimeter of a rectangle
Write a C program to convert minutes into hours and minutes
Interview Questions & Answers
What is the difference between a variable and a constant in C?
What are the data types in C?
What is the difference between = and == in C?
What is the difference between ++i and i++ in C?
What is the use of the sizeof operator in C?
How to swap two numbers in C?