# Program to find the mid-point of a line

Given two coordinates of a line starting is (x1,y1) and ending is (x2,y2) find out the mid-point of a line.

**Examples :**

Input : x1 = –1, y1 = 2, x2 = 3, y2 = –6 Output : 1,–2 Input : x1 = 6.4, y1 = 3 x2 = –10.7, y2 = 4 Output : –2.15, 3.5

**The Midpoint Formula: ** The midpoint of two points, (x1, y2) and (x2, y2) is the point M found by the following formula: **M = ((x _{1}+x_{2})/2 , (y_{1}+y_{2})/2)**

## C++

`// C++ program to find ` `// the midpoint of a line ` `#include<iostream> ` `using` `namespace` `std; ` ` ` `// function to find the ` `// midpoint of a line ` `void` `midpoint(` `int` `x1, ` `int` `x2, ` ` ` `int` `y1, ` `int` `y2) ` `{ ` ` ` `cout << (` `float` `)(x1+x2)/2 << ` ` ` `" , "` `<< (` `float` `)(y1+y2)/2 ; ` `} ` ` ` `// Driver Function to test above ` `int` `main() ` `{ ` ` ` `int` `x1 =-1, y1 = 2 ; ` ` ` `int` `x2 = 3, y2 = -6 ; ` ` ` `midpoint(x1, x2, y1, y2); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to find ` `// the midpoint of a line ` `import` `java.io.*; ` ` ` `class` `GFG ` `{ ` ` ` `// function to find the ` ` ` `// midpoint of a line ` ` ` `static` `void` `midpoint(` `int` `x1, ` `int` `x2, ` ` ` `int` `y1, ` `int` `y2) ` ` ` `{ ` ` ` `System.out.print((x1 + x2) / ` `2` `+ ` ` ` `" , "` `+ (y1 + y2) / ` `2` `) ; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `int` `x1 =-` `1` `, y1 = ` `2` `; ` ` ` `int` `x2 = ` `3` `, y2 = -` `6` `; ` ` ` `midpoint(x1, x2, y1, y2); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## Python3

` ` `# Python3 program to find ` `# the midpoint of a line ` ` ` `# Function to find the ` `# midpoint of a line ` `def` `midpoint(x1, x2, y1, y2): ` ` ` ` ` `print` `((x1 ` `+` `x2) ` `/` `/` `2` `, ` `" , "` `, ` ` ` `(y1 ` `+` `y2) ` `/` `/` `2` `) ` ` ` `# Driver Code ` `x1, y1, x2, y2 ` `=` `-` `1` `, ` `2` `, ` `3` `, ` `-` `6` `midpoint(x1, x2, y1, y2) ` ` ` `# This code is contributed by Anant Agarwal. ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find ` `// the midpoint of a line ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// function to find the ` ` ` `// midpoint of a line ` ` ` `static` `void` `midpoint(` `int` `x1, ` `int` `x2, ` ` ` `int` `y1, ` `int` `y2) ` ` ` `{ ` ` ` `Console.WriteLine((x1 + x2) / 2 + ` ` ` `" , "` `+ (y1 + y2) / 2) ; ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main () ` ` ` `{ ` ` ` `int` `x1 =-1, y1 = 2 ; ` ` ` `int` `x2 = 3, y2 = -6 ; ` ` ` ` ` `midpoint(x1, x2, y1, y2); ` ` ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP program to find ` `// the midpoint of a line ` ` ` `// function to find the ` `// midpoint of a line ` `function` `midpoint(` `$x1` `, ` `$x2` `, ` `$y1` `, ` `$y2` `) ` `{ ` ` ` `echo` `((float)(` `$x1` `+ ` `$x2` `)/2 . ` `" , "` `. ` ` ` `(float)(` `$y1` `+ ` `$y2` `)/2) ; ` `} ` ` ` `// Driver Code ` `$x1` `= -1; ` `$y1` `= 2 ; ` `$x2` `= 3; ` `$y2` `= -6 ; ` `midpoint(` `$x1` `, ` `$x2` `, ` `$y1` `, ` `$y2` `); ` ` ` `// This code is contributed by Ajit. ` `?> ` |

*chevron_right*

*filter_none*

**Output :**

1 , -2

## Recommended Posts:

- Program to find slope of a line
- Program to find line passing through 2 Points
- Find the other end point of a line with given one end and mid
- Find points at a given distance on a line of given slope
- Find an Integer point on a line segment with given two ends
- Find foot of perpendicular from a point in 2 D plane to a Line
- Given n line segments, find if any two segments intersect
- Slope of the line parallel to the line with the given slope
- Program to find sum of 1 + x/2! + x^2/3! +...+x^n/(n+1)!
- Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Program to find the sum of a Series (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + ... + (n*n)
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n
- Program to find GCD or HCF of two numbers
- Program to find LCM of two numbers
- Program to find LCM of 2 numbers without using GCD

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.