Given three lines equation,

a_{1}**x** + b_{1}**y** + c_{1} = 0

a_{2}**x** + b_{2}**y** + c_{2} = 0

a_{3}**x** + b_{3}**y** + c_{3} = 0

The task is to check whether the given three lines are concurrent or not. Three straight lines are said to be concurrent if they pass through a point i.e., they meet at a point.

Examples:

Input : a_{1}= 2, b_{1}= -3, c_{1}= 5 a_{2}= 3, b_{2}= 4, c_{2}= -7 a_{3}= 9, b_{3}= -5, c_{3}= 8 Output : Yes Input : a_{1}= 2, b_{1}= -3, c_{1}= 5 a_{2}= 3, b_{2}= 4, c_{2}= -7 a_{3}= 9, b_{3}= -5, c_{3}= 4 Output : No

Let

a_{1}x + b_{1}y + c_{1} = 0 ………. (1)

a_{2}x + b_{2}y + c_{2} = 0 ………. (2)

a_{3}x + b_{3}y + c_{3} = 0 ………. (3)

Suppose the eqn (i) and (ii) intersets at (x_{1}, y_{1}). Then (x_{1}, y_{1}) will satisfy bothe equations.

Therefore, solving (i) and (ii) using method of cross-multiplication, we get,

(x_{1}/b_{1}c_{2} – b_{2}c_{1}) = (y_{1}/c_{1}a_{2} – c_{2}a_{1}) = (1/a_{1}b_{2} – a_{2}b_{1})

Therefore,

x_{1} = (b_{1}c_{2} – b_{2}c_{1}/a_{1}b_{2} – a_{2}b_{1}) and

y_{1} = (c_{1}a_{2} – c_{2}a_{1}/a_{1}b_{2} – a_{2}b_{1}), a_{1}b_{2} – a_{2}b_{1} != 0

Therefore, the required coodinates of the point of intersection of the lines (i) and (ii) are

(b_{1}c_{2} – b_{2}c_{1}/a_{1}b_{2} – a_{2}b_{1}, c_{1}a_{2} – c_{2}a_{1}/a_{1}b_{2} – a_{2}b_{1})

For, three of line to be concurrent, (x_{1}, y_{1}) must satisfy the equation (iii) as well.

So,

a_{3}x + b_{3}y + c_{3} = 0

=> a_{3}(b_{1}c_{2} – b_{2}c_{1}/a_{1}b_{2} – a_{2}b_{1}) + b_{3}(c_{1}a_{2} – c_{2}a_{1}/a_{1}b_{2} – a_{2}b_{1}) + c_{3} = 0

=> a_{3}(b_{1}c_{2} – b_{2}c_{1}) + b_{3}(c_{1}a_{2} – c_{2}a_{1}) + c_{3}(a_{1}b_{2} – a_{2}b_{1}) = 0

So, we only need to check if above condition satisfy or not.

Below is the implemenatation of this approach:

## C++

`// CPP Program to check if three straight ` `// line are concurrent or not ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Return true if three line are concurrent, ` `// else false. ` `bool` `checkConcurrent(` `int` `a1, ` `int` `b1, ` `int` `c1, ` ` ` `int` `a2, ` `int` `b2, ` `int` `c2, ` ` ` `int` `a3, ` `int` `b3, ` `int` `c3) ` `{ ` ` ` `return` `(a3 * (b1 * c2 - b2 * c1) + ` ` ` `b3 * (c1 * a2 - c2 * a1) + ` ` ` `c3 * (a1 * b2 - a2 * b1) == 0); ` `} ` ` ` `// Driven Program ` `int` `main() ` `{ ` ` ` `int` `a1 = 2, b1 = -3, c1 = 5; ` ` ` `int` `a2 = 3, b2 = 4, c2 = -7; ` ` ` `int` `a3 = 9, b3 = -5, c3 = 8; ` ` ` ` ` `(checkConcurrent(a1, b1, c1, a2, b2, c2, ` ` ` `a3, b3, c3) ? (cout << ` `"Yes"` `) : (cout << ` `"No"` `)); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java Program to check if three straight ` `// line are concurrent or no ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` ` ` `// Return true if three line are concurrent, ` ` ` `// else false. ` ` ` `static` `boolean` `checkConcurrent(` `int` `a1, ` `int` `b1, ` ` ` `int` `c1, ` `int` `a2, ` `int` `b2, ` `int` `c2, ` ` ` `int` `a3, ` `int` `b3, ` `int` `c3) ` ` ` `{ ` ` ` `return` `(a3 * (b1 * c2 - b2 * c1) + ` ` ` `b3 * (c1 * a2 - c2 * a1) + ` ` ` `c3 * (a1 * b2 - a2 * b1) == ` `0` `); ` ` ` `} ` ` ` ` ` `// Driven Program ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `int` `a1 = ` `2` `, b1 = -` `3` `, c1 = ` `5` `; ` ` ` `int` `a2 = ` `3` `, b2 = ` `4` `, c2 = -` `7` `; ` ` ` `int` `a3 = ` `9` `, b3 = -` `5` `, c3 = ` `8` `; ` ` ` ` ` `if` `(checkConcurrent(a1, b1, c1, a2, b2, ` ` ` `c2, a3, b3, c3)) ` ` ` `System.out.println( ` `"Yes"` `); ` ` ` `else` ` ` `System.out.println( ` `"No"` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by anuj_67. ` |

*chevron_right*

*filter_none*

## Python 3

`# Python3 Program to check if three straight ` `# line are concurrent or not ` ` ` `# Return true if three line are concurrent, ` `# else false. ` `def` `checkConcurrent(a1, b1, c1, a2, b2, c2, ` ` ` `a3, b3, c3): ` ` ` ` ` `return` `(a3 ` `*` `(b1 ` `*` `c2 ` `-` `b2 ` `*` `c1) ` `+` ` ` `b3 ` `*` `(c1 ` `*` `a2 ` `-` `c2 ` `*` `a1) ` `+` ` ` `c3 ` `*` `(a1 ` `*` `b2 ` `-` `a2 ` `*` `b1) ` `=` `=` `0` `) ` ` ` ` ` `# Driven Program ` `a1 ` `=` `2` `b1 ` `=` `-` `3` `c1 ` `=` `5` `a2 ` `=` `3` `b2 ` `=` `4` `c2 ` `=` `-` `7` `a3 ` `=` `9` `b3 ` `=` `-` `5` `c3 ` `=` `8` ` ` `if` `(checkConcurrent(a1, b1, c1, a2, b2, c2, ` ` ` `a3, b3, c3)): ` ` ` `print` `(` `"Yes"` `) ` `else` `: ` ` ` `print` `(` `"No"` `) ` ` ` `# This code is contributed by Smitha ` |

*chevron_right*

*filter_none*

## C#

`// C# Program to check if three straight ` `// line are concurrent or no ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` `// Return true if three line are concurrent, ` ` ` `// else false. ` ` ` `static` `bool` `checkConcurrent(` `int` `a1, ` `int` `b1, ` ` ` `int` `c1, ` `int` `a2, ` `int` `b2, ` `int` `c2, ` ` ` `int` `a3, ` `int` `b3, ` `int` `c3) ` ` ` `{ ` ` ` `return` `(a3 * (b1 * c2 - b2 * c1) + ` ` ` `b3 * (c1 * a2 - c2 * a1) + ` ` ` `c3 * (a1 * b2 - a2 * b1) == 0); ` ` ` `} ` ` ` ` ` `// Driven Program ` ` ` `public` `static` `void` `Main () ` ` ` `{ ` ` ` `int` `a1 = 2, b1 = -3, c1 = 5; ` ` ` `int` `a2 = 3, b2 = 4, c2 = -7; ` ` ` `int` `a3 = 9, b3 = -5, c3 = 8; ` ` ` ` ` `if` `(checkConcurrent(a1, b1, c1, a2, b2, ` ` ` `c2, a3, b3, c3)) ` ` ` `Console.WriteLine( ` `"Yes"` `); ` ` ` `else` ` ` `Console.WriteLine( ` `"No"` `); ` ` ` `} ` `} ` ` ` `// This code is contributed by anuj_67. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP Program to check if three straight ` `// line are concurrent or not ` ` ` `// Return true if three line are ` `// concurrent, else false. ` `function` `checkConcurrent(` `$a1` `, ` `$b1` `, ` `$c1` `, ` ` ` `$a2` `, ` `$b2` `, ` `$c2` `, ` ` ` `$a3` `, ` `$b3` `, ` `$c3` `) ` `{ ` ` ` `return` `(` `$a3` `* (` `$b1` `* ` `$c2` `- ` `$b2` `* ` `$c1` `) + ` ` ` `$b3` `* (` `$c1` `* ` `$a2` `- ` `$c2` `* ` `$a1` `) + ` ` ` `$c3` `* (` `$a1` `* ` `$b2` `- ` `$a2` `* ` `$b1` `) == 0); ` `} ` ` ` ` ` `// Driver Code ` ` ` `$a1` `= 2; ` `$b1` `= -3; ` `$c1` `= 5; ` ` ` `$a2` `= 3; ` `$b2` `= 4; ` `$c2` `= -7; ` ` ` `$a3` `= 9; ` `$b3` `= -5; ` `$c3` `= 8; ` ` ` ` ` `if` `(checkConcurrent(` `$a1` `, ` `$b1` `, ` `$c1` `, ` `$a2` `, ` `$b2` `, ` ` ` `$c2` `, ` `$a3` `, ` `$b3` `, ` `$c3` `)) ` ` ` `echo` `"Yes"` `; ` ` ` `else` ` ` `echo` `"No"` `; ` ` ` `// This code is contributed by anuj_67. ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

Yes

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:

- Check whether two straight lines are orthogonal or not
- Check if given two straight lines are identical or not
- Maximum points of intersections possible among X circles and Y straight lines
- Count of rectangles possible from N and M straight lines parallel to X and Y axis respectively
- Count straight lines intersecting at a given point
- Number of triangles formed from a set of points on three lines
- Python - Find the maximum number of triangles with given points on three lines
- Check whether a straight line can be formed using N co-ordinate points
- Number of quadruples where the first three terms are in AP and last three terms are in GP
- Check whether a number has exactly three distinct factors or not
- Check whether triangle is valid or not if three points are given
- Find whether only two parallel lines contain all coordinates points or not
- Number of lines from given N points not parallel to X or Y axis
- 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
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Area of triangle formed by the axes of co-ordinates and a given straight line
- Straight-line Number
- Puzzle | Place numbers 1 to 9 in a Circle such that sum of every triplet in straight line is 15
- Check if a number can be written as sum of three consecutive integers

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.