Find number of candidates in the Exam

Given the last rank ‘L’ and number of candidates at the last rank ‘T’, the task is to find the total number of candidates in Exam.

Input: L = 5, T = 1
Output: 5

Input: L = 10, T = 2
Output: 11

Approach:

  1. Suppose L = 5 and T = 2.
  2. Then there can be many possible rank combinations, like 1, 2, 3, 3, 5, 5.
  3. So now in this, as you can see the last rank is 5 and there are 2 students at rank 5,
  4. Therefore, total number of candidates = 6.
  5. This can be understood by a simple formula:
    L+T-1

Below is the Implementation of Above Approach.

C++



filter_none

edit
close

play_arrow

link
brightness_4
code

// C++ program to find total number of candidates
// in an Exam from given last rank
// and Number of student at this last rank.
  
#include <iostream>
using namespace std;
  
// Function to find total number of
// Participants in Exam.
int findParticipants(int L, int T)
{
    return (L + T - 1);
}
  
// Driver code
int main()
{
    int L = 10, T = 2;
    cout << findParticipants(L, T);
  
    return 0;
}

chevron_right


Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 program to find total number 
# of candidates in an Exam from given last rank 
# and Number of student at this last rank. 
  
# Function to find total number of 
# Participants in Exam. 
def findParticipants(L, T) : 
  
    return (L + T - 1); 
  
# Driver code 
if __name__ == "__main__"
  
    L = 10; T = 2
    print(findParticipants(L, T)); 
      
# This code is contributed by AnkitRai01

chevron_right


Output:

11


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 : AnkitRai01, shubham_singh



Article Tags :

1


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