- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Position of a person diametrically opposite on a circle in C++

In this problem, we are given two integers N and M. there is a circle and N people are standing on it. M denotes the position of a person. Our task is to print the position of the person opposite to M.

Let’s take an example to understand the problem,

**Input** − N = 6, M = 3

**Output** − 6

**Explanation** −

To solve this problem, there will be two cases, one if the position is greater than half the position (second half), the opposition will be the first half and vise versa.

Let’s create a formula for this mathematically,

**Case 1** − if m > n/2, the position of the opposite person is m - (n/2)

**Case 2** − if m =< n/2, the position of the opposite person is m + (n/2)

## Example

Program to show the illustration of our solution,

#include <iostream> using namespace std; void printOppositePosition(int n, int m) { int pos; if (m > (n / 2)) pos = (m - (n / 2)); else pos = (m + (n / 2)); cout<<pos; } int main() { int N = 8, M = 4; cout<<"The position of person opposite to person at position "<<M<<" when "<<N<<" people are standing in a circle is "; printOppositePosition(N, M); return 0; }

## Output

The position of person opposite to person at position 4 when 8 people are standing in a circle is 8

- Related Articles
- A boy of mass ( 40 mathrm{~kg} ) moves on a circular track of radius ( 21 mathrm{~m} ). Find displacement and distance when initial and final position are diametrically opposite points.
- Determine the position of the third person on regular N sided polygon in C++?
- Determine the position of the third person on regular N sided polygon in C++ Program
- Prove that opposite sides of a quadrilateral circumscribing a circle subtend supplementary angles at the centre of the circle.
- How will you describe the position of a table lamp on your study table to another person?
- Queries on count of points lie inside a circle in C++
- Focal length of a concave mirror is(a) negative (b) positive (c) depends on the position of object (d) depends on the position of image
- How to set the position of a Circle from left using FabricJS?
- Convert characters of a string to opposite case in C++
- Draw any circle and mark points ( mathrm{A}, mathrm{B} ) and ( mathrm{C} ) such that(a) ( mathrm{A} ) is on the circle.(b) ( mathrm{B} ) is in the interior of the circle.(c) ( mathrm{C} ) is in the exterior of the circle.
- Area of a Circumscribed Circle of a Square in C++
- Program to find number of possible position in n-person line with few person at front and back in Python
- Construct a tangent of a circle of radius 4cm from a point on the concentric circle of radius 6 cm.
- A brick is kept in three different ways on a table as shown in the figure. The pressure exerted by the brick on the table will be$(a)$. maximum in position A $(b)$. maximum in position C$(c)$. maximum in position B $(d)$. equal in all cases"
- Setting the position on a button in Tkinter Python?

Advertisements