# Number of matches required to find the winner

Given a number **N** which represent the number of players participating in Badminton match. The task is to determine the Number of matches required to determine the Winner. In each Match 1 player is knocked out.

**Examples:**

Input:N = 4Output:Matches played = 3 (As after each match only N - 1 players left)Input:N = 9Output:Matches played = 8

**Approach:** Since, after each match one player is knocked out. So to get the winner, **n-1** players should be knocked out and for which **n-1** matches to be played.

Below is the implementation of the above approach:

## C++

`// C++ implementation of above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function that will tell ` `// no. of matches required ` `int` `noOfMatches(` `int` `N) ` `{ ` ` ` `return` `N - 1; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `N = 8; ` ` ` ` ` `cout << ` `"Matches played = "` `<< noOfMatches(N); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of above approach ` `import` `java.io.*; ` ` ` `class` `GFG ` `{ ` ` ` `// Function that will tell ` `// no. of matches required ` `static` `int` `noOfMatches(` `int` `N) ` `{ ` ` ` `return` `N - ` `1` `; ` `} ` ` ` `// Driver code ` `public` `static` `void` `main (String[] args) ` `{ ` ` ` `int` `N = ` `8` `; ` ` ` `System.out.println (` `"Matches played = "` `+ ` ` ` `noOfMatches(N)); ` `} ` `} ` ` ` `// This code is contributed by jit_t ` |

*chevron_right*

*filter_none*

## Python3

`# Python 3 implementation of ` `# above approach ` ` ` `# Function that will tell ` `# no. of matches required ` `def` `noOfMatches(N) : ` ` ` ` ` `return` `N ` `-` `1` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `N ` `=` `8` ` ` ` ` `print` `(` `"Matches played ="` `, ` ` ` `noOfMatches(N)) ` ` ` `# This code is contributed ` `# by ANKITRAI1 ` |

*chevron_right*

*filter_none*

## C#

`//C# implementation of above approach ` `using` `System; ` ` ` `public` `class` `GFG{ ` ` ` ` ` `// Function that will tell ` `// no. of matches required ` `static` `int` `noOfMatches(` `int` `N) ` `{ ` ` ` `return` `N - 1; ` `} ` ` ` `// Driver code ` ` ` ` ` `static` `public` `void` `Main (){ ` ` ` `int` `N = 8; ` ` ` `Console.WriteLine(` `"Matches played = "` `+ ` ` ` `noOfMatches(N)); ` `} ` `} ` ` ` `// This code is contributed by ajit ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of above approach ` ` ` `// Function that will tell ` `// no. of matches required ` `function` `noOfMatches(` `$N` `) ` `{ ` ` ` `return` `(` `$N` `- 1); ` `} ` ` ` `// Driver code ` `$N` `= 8; ` `echo` `"Matches played = "` `, ` ` ` `noOfMatches(` `$N` `); ` ` ` `// This code is contributed by akt_mit ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Matches played = 7

## Recommended Posts:

- Python String Methods | Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)
- Program to find sum of elements in a given array
- Program to find largest element in an array
- Program to find GCD or HCF of two numbers
- Program to find LCM of two numbers
- Program for factorial of a number
- Program to find transpose of a matrix
- Program to find area of a triangle
- Program to find area of a circle
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n
- Find all angles of a given triangle
- Find count of digits in a number that divide the number
- Check if a number can be written as sum of three consecutive integers
- Find a time for which angle between hour and minute hands is given theta
- Changing One Clock Time to Other Time in Minimum Number of Operations

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.