Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Find number of candidates in the Exam

  • Difficulty Level : Basic
  • Last Updated : 27 May, 2021

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

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

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

Approach: 

Hey! Looking for some great resources suitable for young ones? You've come to the right place. Check out our self-paced courses designed for students of grades I-XII

Start with topics like Python, HTML, ML, and learn to make some games and apps all with the help of our expertly designed content! So students worry no more, because GeeksforGeeks School is now here!

 

  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, the total number of candidates is 6.
  5. This can be understood by a simple formula:
L+T-1

Below is the implementation of the above approach.  

C++




// 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;
}

Java




// Java program to find total number of
// candidates in an Exam from given last rank
// and Number of student at this last rank.
class GFG
{
 
    // Function to find total number of
    // Participants in Exam.
    static int findParticipants(int L, int T)
    {
        return (L + T - 1);
    }
 
    // Driver code
    public static void main(String args[])
    {
        int L = 10, T = 2;
        System.out.print(findParticipants(L, T));
    }
}
 
// This code is contributed by Gowtham Yuvaraj

Python3




# 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

C#




// C# program to find total number of
// candidates in an Exam from given last rank
// and Number of student at this last rank.
using System;
 
class GFG
{
 
    // Function to find total number of
    // Participants in Exam.
    static int findParticipants(int L, int T)
    {
        return (L + T - 1);
    }
 
    // Driver code
    public static void Main()
    {
        int L = 10, T = 2;
        Console.Write(findParticipants(L, T));
    }
}
 
// This code is contributed by Gowtham Yuvaraj

Javascript




<script>
 
// Javascript 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.
function findParticipants(L, T)
{
    return (L + T - 1);
}
 
// Driver code
var L = 10, T = 2;
document.write( findParticipants(L, T));
 
</script>
Output: 
11

 




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!