# Program to calculate Percentile of a student based on rank

Given the rank of a student and the total number of students appearing in an examination, the task is to find the percentile of the student.

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

Examples:

Input: Rank: 805, Total Number of Students Appeared: 97481
Output: 99.17
Explaination:
((97481 – 805) / 97481) * 100 = 99.17

Input: Rank: 65, Total Number of Students Appeared: 100
Output: 35
Explaination:
((100 – 65) / 100) * 100 = 35

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach
The formula to calculate the percentile when the rank of the student and the total number of students appeared is given is:

((Total Students – Rank) / Total Students) * 100

Below is the implementation of the above formula:

## C++

 `// C++ program to calculate Percentile ` `// of a student based on rank ` ` `  `#include ` `using` `namespace` `std; ` ` `  `// Program to calculate the percentile ` `float` `getPercentile(``int` `rank, ``int` `students) ` `{ ` `    ``// flat variable to store the result ` `    ``float` `result = ``float``(students - rank) ` `                   ``/ students * 100; ` ` `  `    ``// calculate and return the percentile ` `    ``return` `result; ` `} ` ` `  `// Driver Code ` `int` `main() ` `{ ` `    ``int` `your_rank = 805; ` `    ``int` `total_students = 97481; ` ` `  `    ``cout << getPercentile( ` `        ``your_rank, total_students); ` `} `

## Java

 `// Java program to calculate Percentile ` `// of a student based on rank ` `import` `java.util.*; ` ` `  `class` `GFG{ ` `  `  `// Program to calculate the percentile ` `static` `float` `getPercentile(``int` `rank, ``int` `students) ` `{ ` `    ``// flat variable to store the result ` `    ``float` `result = (``float``)(students - rank) ` `                   ``/ students * ``100``; ` `  `  `    ``// calculate and return the percentile ` `    ``return` `result; ` `} ` `  `  `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` `    ``int` `your_rank = ``805``; ` `    ``int` `total_students = ``97481``; ` `  `  `    ``System.out.print(getPercentile( ` `        ``your_rank, total_students)); ` `} ` `} ` ` `  `// This code is contributed by Princi Singh `

## Python3

 `# Python3 program to calculate Percentile  ` `# of a student based on rank  ` ` `  `# Program to calculate the percentile  ` `def` `getPercentile(rank, students) :  ` ` `  `    ``# flat variable to store the result  ` `    ``result ``=` `(students ``-` `rank) ``/` `students ``*` `100``;  ` ` `  `    ``# calculate and return the percentile  ` `    ``return` `result;  ` ` `  `# Driver Code  ` `if` `__name__ ``=``=` `"__main__"` `:  ` ` `  `    ``your_rank ``=` `805``;  ` `    ``total_students ``=` `97481``;  ` ` `  `    ``print``(getPercentile(your_rank, total_students));  ` ` `  `# This code is contributed by Yash_R `

## C#

 `// C# program to calculate Percentile ` `// of a student based on rank ` `using` `System; ` ` `  `class` `GFG{ ` `   `  `// Program to calculate the percentile ` `static` `float` `getPercentile(``int` `rank, ``int` `students) ` `{ ` `    ``// flat variable to store the result ` `    ``float` `result = (``float``)(students - rank) ` `                   ``/ students * 100; ` `   `  `    ``// calculate and return the percentile ` `    ``return` `result; ` `} ` `   `  `// Driver Code ` `public` `static` `void` `Main(String[] args) ` `{ ` `    ``int` `your_rank = 805; ` `    ``int` `total_students = 97481; ` `   `  `    ``Console.Write(getPercentile( ` `        ``your_rank, total_students)); ` `} ` `} ` ` `  `// This code is contributed by Princi Singh `

Output:

```99.1742
```

Performance Analysis:

• Time Complexity: In the above approach, we are able to calculate percentile using a formula in constant time, so the time complexity is O(1).
• Auxiliary Space Complexity: In the above approach, we are not using any extra space apart from a few constant size variables, so Auxiliary space complexity is O(1).

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Improved By : Yash_R, princi singh

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.