VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-calculate-percentile-of-students/

⇱ Program to calculate Percentile of Students - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to calculate Percentile of Students

Last Updated : 19 Jul, 2022

Given an array containing marks of students, the task is to calculate the percentile of the students. The percentile is calculated according to the following rule: 
 

The percentile of a student is the % of the number of students having marks less than him/her.


Examples: 
 

Input: arr[] = { 12, 60, 80, 71, 30 }
Output: { 0, 50, 100, 75, 25 }
Explanation: 
Percentile of Student 1 = 0/4*100 = 0 (out of other 4 students no one has marks less than this student) 
Percentile of Student 2 = 2/4*100 = 50 (out of other 4 students, 2 have marks less than this student) 
Percentile of Student 3 = 4/4*100 = 100 (out of other 4 students, all 4 have marks less than this student) 
Percentile of Student 4 = 3/4*100 = 75 (out of other 4 students, 3 have marks less than this student) 
Percentile of Student 5 = 1/4*100 = 25 (out of other 4 students only 1 has marks less than this student) 
 


 


Approach: 
 

  • So basically, the percentile is a number where a certain percentage of scores fall below that number. 
     
  • For example: If in an examination a student's percentile is 75 then it means that the student has scored more than 75% of students who took the test. 
     
  • Now, in order to calculate percentile we have the following formula:
    PERCENTILE = (NUMBER OF STUDENTS WHO SCORED BELOW OR EQUAL TO THE DESIRED STUDENT/ TOTAL NUMBER OF STUDENTS - 1) * 100 
     


Below is the implementation of the above approach:
 


Output: 
Percentile of Student 1 = 0
Percentile of Student 2 = 50
Percentile of Student 3 = 100
Percentile of Student 4 = 75
Percentile of Student 5 = 25

 

Time Complexity: O(n2)

Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: