Program To Calculate Percentage In C



Percent means per cent (hundreds), i.e., a ratio of the parts out of 100. The symbol of percent is %. We generally count percentage of marks obtained, return on investment etc. Percentage can go beyond 100% also.

For Example − assuming that we have total and a part. So we say what part is what percent of total and should be calculated as −

percentage = ( part / total ) × 100

Algorithm

Algorithm to find percentage is as follows −

START
   Step 1 → Collect values for part and total
   Step 2 → Apply formula { percentage = ( part / total ) × 100 }
   Step 3 → Display percentage
STOP

Pseudocode

Pseudocode for the algorithm can be written as −

procedure percentage()
   
   VAR value, total
   percentage = value / total * 100
   RETURN percentage

end procedure

Implementation

Implementation of this algorithm is given below −

#include <stdio.h>

int main() {
   float percentage;
   int total_marks = 1200;
   int scored = 1122;

   percentage = (float)scored / total_marks * 100.0;

   printf("Percentage = %.2f%%", percentage);

   return 0;
}

Output

Output of the program should be −

Percentage = 93.50% 
mathematical_programs_in_c.htm
Advertisements