Dado el último rango ‘L’ y el número de candidatos en el último rango ‘T’, la tarea es encontrar el número total de candidatos en el Examen.
Input: L = 5, T = 1 Output: 5 Input: L = 10, T = 2 Output: 11
Acercarse:
- Supongamos que L = 5 y T = 2.
- Entonces puede haber muchas combinaciones de rango posibles, como 1, 2, 3, 3, 5, 5.
- Entonces ahora en esto, como puede ver, el último rango es 5 y hay 2 estudiantes en el rango 5,
- Por lo tanto, el número total de candidatos es 6.
- Esto se puede entender con una fórmula simple:
L+T-1
A continuación se muestra la implementación del enfoque anterior.
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>
Producción:
11