Given a straight line which passes through a given point **(x _{0}, y_{0})** such that this point bisects the line segment in two equal line segments. The task is to find the equation of this straight line.

**Examples:**

Input:x_{0}= 4, y_{0}= 3Output:3x + 4y = 24

Input:x_{0}= 7, y_{0}= 12Output:12x + 7y = 168

**Approach:**

Let **PQ** be the line and **AB** be the line segment between the axes. The x-intercept and y-intercept are **a** & **b** respectively.

Now, as **C(x _{0}, y_{0})** bisects

**AB**so,

**x**i.e.

_{0}= (a + 0) / 2**a = 2x**

_{0}Similiarly,

**y**i.e.

_{0}= (0 + b) / 2**b = 2y**

_{0}We know that the equation of a straight line in intecept form is,

x / a + y / b = 1

Here,a = 2x&_{0}b = 2y_{0}

So,x / 2x_{0}+ y / 2y_{0}= 1

or,x / x_{0}+ y / y_{0}= 2

Therefore,x * y_{0}+ y * x_{0}= 2 * x_{0}* y_{0}

Below is the implementation of the above approach:

`// C++ implementation of the approach ` `#include <iostream> ` `using` `namespace` `std; `
` ` `// Function to print the equation ` `// of the required line ` `void` `line(` `double` `x0, ` `double` `y0) `
`{ ` ` ` `double` `c = 2 * y0 * x0; `
` ` `cout << y0 << ` `"x"`
` ` `<< ` `" + "` `<< x0 << ` `"y = "` `<< c; `
`} ` ` ` `// Driver code ` `int` `main() `
`{ ` ` ` `double` `x0 = 4, y0 = 3; `
` ` `line(x0, y0); `
` ` ` ` `return` `0; `
`} ` |

*chevron_right*

*filter_none*

`// Java implementation of the approach ` `class` `GFG `
`{ ` ` ` `// Function to print the equation ` `// of the required line ` `static` `void` `line(` `double` `x0, ` `double` `y0) `
`{ ` ` ` `double` `c = (` `int` `)(` `2` `* y0 * x0); `
` ` `System.out.println(y0 + ` `"x"` `+ ` `" + "` `+ `
` ` `x0 + ` `"y = "` `+ c); `
`} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) `
`{ ` ` ` `double` `x0 = ` `4` `, y0 = ` `3` `; `
` ` `line(x0, y0); `
`} ` `} ` ` ` `// This code is contributed ` `// by Code_Mech ` |

*chevron_right*

*filter_none*

`# Python 3 implementation of the approach ` ` ` `# Function to print the equation ` `# of the required line ` `def` `line(x0, y0): `
` ` `c ` `=` `2` `*` `y0 ` `*` `x0 `
` ` `print` `(y0, ` `"x"` `, ` `"+"` `, x0, ` `"y="` `, c) `
` ` `# Driver code ` `if` `__name__ ` `=` `=` `'__main__'` `: `
` ` `x0 ` `=` `4`
` ` `y0 ` `=` `3`
` ` `line(x0, y0) `
` ` `# This code is contributed by ` `# Surendra_Gangwar ` |

*chevron_right*

*filter_none*

`// C# implementation of the approach ` `using` `System; `
` ` `class` `GFG `
`{ ` ` ` `// Function to print the equation ` `// of the required line ` `static` `void` `line(` `double` `x0, ` `double` `y0) `
`{ ` ` ` `double` `c = (` `int` `)(2 * y0 * x0); `
` ` `Console.WriteLine(y0 + ` `"x"` `+ ` `" + "` `+ `
` ` `x0 + ` `"y = "` `+ c); `
`} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) `
`{ ` ` ` `double` `x0 = 4, y0 = 3; `
` ` `line(x0, y0); `
`} ` `} ` ` ` `/* This code contributed by PrinciRaj1992 */` |

*chevron_right*

*filter_none*

`<?php ` `// PHP implementation of the approach ` ` ` `// Function to print the equation ` `// of the required line ` `function` `line(` `$x0` `, ` `$y0` `) `
`{ ` ` ` `$c` `= 2 * ` `$y0` `* ` `$x0` `; `
` ` `echo` `$y0` `, ` `"x"` `,` `" + "` `, `
` ` `$x0` `, ` `"y = "` `, ` `$c` `; `
`} ` ` ` `// Driver code ` `$x0` `= 4; ` `$y0` `= 3; `
`line(` `$x0` `, ` `$y0` `); `
` ` `// This code is contributed by Ryuga ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

3x + 4y = 24

Rated as one of the most sought after skills in the industry, own the basics of coding with our **C++ STL** Course and master the very concepts by intense problem-solving.

## Recommended Posts:

- Minimum points to be selected such that removal of line segments passing through them empties given array
- Given n line segments, find if any two segments intersect
- Maximum distinct lines passing through a single point
- Find X and Y intercepts of a line passing through the given points
- Find the equation of plane which passes through two points and parallel to a given axis
- Passing by pointer Vs Passing by Reference in C++
- Draw an ellipse divided by straight line into two colored part in C++ Graphics
- Count straight lines intersecting at a given point
- How to check if two given line segments intersect?
- Represent a given set of points by the best possible straight line
- Length of the normal from origin on a straight line whose intercepts are given
- Area of triangle formed by the axes of co-ordinates and a given straight line
- Find if there exists multiple ways to draw line through (x, y) to cut rectangle in equal halfs
- Satisfy the parabola when point (A, B) and the equation is given
- Straight-line Number
- Puzzle | Place numbers 1 to 9 in a Circle such that sum of every triplet in straight line is 15
- Check whether a straight line can be formed using N co-ordinate points
- Count number of triangles cut by the given horizontal and vertical line segments
- Count of ways to split a given number into prime segments
- Check if given two straight lines are identical or not

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.