There are **n** people standing on the circumference of a circle. Given the position of a persom **m**, the task is to find the position of the person standing diametrically opposite to **m** on the circle.

**Examples:**

Input:n = 6, m = 2

Output:5

Position 5 is opposite to 2 when there are 6 positions in total

Input:n = 8, m = 5

Output:1

**Approach:** There are two cases:

- If
**m > n / 2**then answer will always be**m – (n / 2)**. - If
**m ≤ n / 2**then answer will always be**m + (n / 2)**.

Below is the implementation of the above approach:

## C++

`// C++ implementation of the approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to return the required position ` `int` `getPosition(` `int` `n, ` `int` `m) ` `{ ` ` ` `if` `(m > (n / 2)) ` ` ` `return` `(m - (n / 2)); ` ` ` ` ` `return` `(m + (n / 2)); ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 8, m = 5; ` ` ` `cout << getPosition(n, m); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the approach ` `class` `Sol ` `{ ` ` ` `// Function to return the required position ` `static` `int` `getPosition(` `int` `n, ` `int` `m) ` `{ ` ` ` `if` `(m > (n / ` `2` `)) ` ` ` `return` `(m - (n / ` `2` `)); ` ` ` ` ` `return` `(m + (n / ` `2` `)); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String args[]) ` `{ ` ` ` `int` `n = ` `8` `, m = ` `5` `; ` ` ` `System.out.println(getPosition(n, m)); ` ` ` `} ` `} ` `// This code is contributed by Arnab Kundu ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the approach ` ` ` `# Function to return the ` `# required position ` `def` `getPosition(n, m): ` ` ` ` ` `if` `(m > (n ` `/` `/` `2` `)) : ` ` ` `return` `(m ` `-` `(n ` `/` `/` `2` `)) ` ` ` ` ` `return` `(m ` `+` `(n ` `/` `/` `2` `)) ` ` ` `# Driver code ` `n ` `=` `8` `m ` `=` `5` `print` `(getPosition(n, m)) ` ` ` `# This code is contributed ` `# by ihritik ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the approach ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to return the required position ` `static` `int` `getPosition(` `int` `n, ` `int` `m) ` `{ ` ` ` `if` `(m > (n / 2)) ` ` ` `return` `(m - (n / 2)); ` ` ` ` ` `return` `(m + (n / 2)); ` `} ` ` ` ` ` `// Driver code ` ` ` `static` `public` `void` `Main () ` ` ` `{ ` ` ` ` ` `int` `n = 8, m = 5; ` ` ` `Console.WriteLine(getPosition(n, m)); ` ` ` `} ` `} ` ` ` `// This code is contributed by ajit. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to return the ` `// required position ` `function` `getPosition(` `$n` `, ` `$m` `) ` `{ ` ` ` ` ` `if` `(` `$m` `> (` `$n` `/ 2)) ` ` ` `return` `(` `$m` `- (` `$n` `/ 2)); ` ` ` ` ` `return` `(` `$m` `+ (` `$n` `/ 2)); ` `} ` ` ` `// Driver code ` `$n` `= 8; ` `$m` `= 5; ` `echo` `getPosition(` `$n` `, ` `$m` `); ` ` ` `// This code is contributed ` `// by ihritik ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

1

**Time Complexity:** O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Number of hours after which the second person moves ahead of the first person if they travel at a given speed
- Lucky alive person in a circle | Code Solution to sword puzzle
- Determine the position of the third person on regular N sided polygon
- Convert characters of a string to opposite case
- Time until distance gets equal to X between two objects moving in opposite direction
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
- Find two vertices of an isosceles triangle in which there is rectangle with opposite corners (0, 0) and (X, Y)
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Find the area of quadrilateral when diagonal and the perpendiculars to it from opposite vertices are given
- Check if roots of a Quadratic Equation are numerically equal but opposite in sign or not
- Find the vertex diagonally opposite to the vertex M from an N-sided polygon
- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- Equation of circle when three points on the circle are given
- Check if a circle lies inside another circle or not
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Area of the circle that has a square and a circle inscribed in it
- Distributing M items in a circle of size N starting from K-th position
- Number of handshakes such that a person shakes hands only once
- Number of different positions where a person can stand

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.