Given two endpoint of diameter of a circle (x1, y1) and (x2, y2) find out the center of a circle.

**Examples :**

Input : x1 = -9, y1 = 3, and x2 = 5, y2 = –7 Output : -2, –2 Input : x1 = 5, y1 = 3 and x2 = –10 y2 = 4 Output : –2.5, 3.5

**Midpoint Formula:
** The midpoint of two points, (x1, y2) and (x2, y2) is :

**M = ((x**

_{1}+ x_{2}) / 2, (y_{1}+ y_{2}) / 2)The center of the circle is the mid point of its diameter so we calculate the mid point of its diameter by using midpoint formula.

## C++

`// C++ program to find the ` `// center of the circle ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// function to find the ` `// center of the circle ` `void` `center(` `int` `x1, ` `int` `x2, ` ` ` `int` `y1, ` `int` `y2) ` `{ ` ` ` ` ` `cout << (` `float` `)(x1 + x2) / 2 << ` ` ` `", "` `<< (` `float` `)(y1 + y2) / 2; ` `} ` ` ` `// Driven Program ` `int` `main() ` `{ ` ` ` `int` `x1 = -9, y1 = 3, x2 = 5, y2 = -7; ` ` ` `center(x1, x2, y1, y2); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find the ` `// center of the circle ` `class` `GFG { ` ` ` ` ` `// function to find the ` ` ` `// center of the circle ` ` ` `static` `void` `center(` `int` `x1, ` `int` `x2, ` ` ` `int` `y1, ` `int` `y2) ` ` ` `{ ` ` ` ` ` `System.out.print((` `float` `)(x1 + x2) / ` `2` ` ` `+ ` `", "` `+ (` `float` `)(y1 + y2) / ` `2` `); ` ` ` `} ` ` ` ` ` `// Driver Program to test above function ` ` ` `public` `static` `void` `main(String arg[]) { ` ` ` ` ` `int` `x1 = -` `9` `, y1 = ` `3` `, x2 = ` `5` `, y2 = -` `7` `; ` ` ` `center(x1, x2, y1, y2); ` ` ` `} ` `} ` ` ` `// This code is contributed by Anant Agarwal. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to find ` `# the center of the circle ` ` ` `# Function to find the ` `# center of the circle ` `def` `center(x1, x2, y1, y2) : ` ` ` ` ` `print` `(` `int` `((x1 ` `+` `x2) ` `/` `2` `), end` `=` `"") ` ` ` `print` `(` `","` `, ` `int` `((y1 ` `+` `y2) ` `/` `2` `) ) ` ` ` `# Driver Code ` `x1 ` `=` `-` `9` `; y1 ` `=` `3` `; x2 ` `=` `5` `; y2 ` `=` `-` `7` `center(x1, x2, y1, y2) ` ` ` `# This code is contributed by Smitha Dinesh Semwal ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find the ` `// center of the circle ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// function to find the ` ` ` `// center of the circle ` ` ` `static` `void` `center(` `int` `x1, ` `int` `x2, ` ` ` `int` `y1, ` `int` `y2) ` ` ` `{ ` ` ` ` ` `Console.WriteLine((` `float` `)(x1 + x2) / 2 ` ` ` `+ ` `", "` `+ (` `float` `)(y1 + y2) / 2); ` ` ` `} ` ` ` ` ` `// Driver Program to test above function ` ` ` `public` `static` `void` `Main() { ` ` ` ` ` `int` `x1 = -9, y1 = 3, x2 = 5, y2 = -7; ` ` ` `center(x1, x2, y1, y2); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find the ` `// center of the circle ` ` ` `// function to find the ` `// center of the circle ` `function` `center(` `$x1` `, ` `$x2` `, ` `$y1` `, ` `$y2` `) ` `{ ` ` ` ` ` `echo` `((float)(` `$x1` `+ ` `$x2` `) / 2 . ` `", "` `. ` ` ` `(float)(` `$y1` `+ ` `$y2` `) / 2); ` `} ` ` ` `// Driven Code ` `$x1` `= -9; ` `$y1` `= 3; ` `$x2` `= 5; ` `$y2` `= -7; ` `center(` `$x1` `, ` `$x2` `, ` `$y1` `, ` `$y2` `); ` ` ` `// This code is contributed by Ajit. ` `?> ` |

*chevron_right*

*filter_none*

**Output :**

-2, -2

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:

- Program to calculate area of inner circle which passes through center of outer circle and touches its circumference
- 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
- Distance of chord from center when distance between center and another equal length chord is given
- Find the other-end coordinates of diameter in a circle
- Find the Diameter or Longest chord of a Circle
- Length of the chord the circle if length of the another chord which is equally inclined through the diameter is given
- Minimum revolutions to move center of a circle to a target
- Length of the chord of the circle whose radius and the angle subtended at the center by the chord is given
- Find area of the larger circle when radius of the smaller circle and difference in the area is given
- Program to find the diameter, cycles and edges of a Wheel Graph
- Equation of circle when three points on the circle are given
- Check if a circle lies inside another circle or not
- Area of the circle that has a square and a circle inscribed in it
- Puzzle | Connect 9 circles each arranged at center of a Matrix using 3 straight lines
- Python String Methods | Set 2 (len, count, center, ljust, rjust, isalpha, isalnum, isspace & join)
- Farthest distance of a 0 from the center of a 2-D matrix
- Check whether two convex regular polygon have same center or not
- Number of cycles formed by joining vertices of n sided polygon at the center
- Program to find area of a circle
- Find minimum radius such that atleast k point lie inside the circle

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.