# Check whether the point (x, y) lies on a given line

Given the values of m and c for the equation of a line y = (m * x) + c, the task is to find whether the point (x, y) lies on the given line.

Examples:

Input: m = 3, c = 2, x = 1, y = 5
Output: Yes
m * x + c = 3 * 1 + 2 = 3 + 2 = 5 which is equal to y
Hence, the given point satisfies the line’s equation

Input: m = 5, c = 2, x = 2, y = 5
Output: No

## Recommended: Please try your approach on {IDE} first, before moving on to the solution.

Approach: In order for the given point to lie on the line, it must satisfy the equation of the line. Check whether y = (m * x) + c holds true.

Below is the implementation of the above approach:

## C++

 `// C++ implementation of the approach ` `#include ` `using` `namespace` `std; ` ` `  `// Function that return true if ` `// the given point lies on the given line ` `bool` `pointIsOnLine(``int` `m, ``int` `c, ``int` `x, ``int` `y) ` `{ ` `    ``// If (x, y) satisfies the equation of the line ` `    ``if` `(y == ((m * x) + c)) ` `        ``return` `true``; ` ` `  `    ``return` `false``; ` `} ` ` `  `// Driver code ` `int` `main() ` `{ ` `    ``int` `m = 3, c = 2; ` `    ``int` `x = 1, y = 5; ` ` `  `    ``if` `(pointIsOnLine(m, c, x, y)) ` `        ``cout << ``"Yes"``; ` `    ``else` `        ``cout << ``"No"``; ` `} `

## Java

 `// Java implementation of the approach ` ` `  `class` `GFG ` `{ ` ` `  `// Function that return true if ` `// the given point lies on the given line ` `static` `boolean` `pointIsOnLine(``int` `m, ``int` `c, ` `                        ``int` `x, ``int` `y) ` `{ ` `    ``// If (x, y) satisfies the equation  ` `    ``// of the line ` `    ``if` `(y == ((m * x) + c)) ` `        ``return` `true``; ` ` `  `    ``return` `false``; ` `} ` ` `  `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` `    ``int` `m = ``3``, c = ``2``; ` `    ``int` `x = ``1``, y = ``5``; ` ` `  `    ``if` `(pointIsOnLine(m, c, x, y)) ` `        ``System.out.print(``"Yes"``); ` `    ``else` `        ``System.out.print(``"No"``); ` `} ` `} ` ` `  `// This code has been contributed by 29AjayKumar `

## Python3

 `# Python3 implementation of the approach  ` ` `  `# Function that return true if the  ` `# given point lies on the given line  ` `def` `pointIsOnLine(m, c, x, y): ` `     `  `    ``# If (x, y) satisfies the  ` `    ``# equation of the line  ` `    ``if` `(y ``=``=` `((m ``*` `x) ``+` `c)):  ` `        ``return` `True``;  ` ` `  `    ``return` `False``;  ` ` `  `# Driver code  ` `m ``=` `3``; c ``=` `2``;  ` `x ``=` `1``; y ``=` `5``;  ` ` `  `if` `(pointIsOnLine(m, c, x, y)):  ` `    ``print``(``"Yes"``);  ` `else``: ` `    ``print``(``"No"``);  ` `     `  `# This code is contributed by mits `

## C#

 `// C# implementation of the approach ` `using` `System; ` ` `  `class` `GFG ` `{ ` ` `  `// Function that return true if ` `// the given point lies on the given line ` `static` `bool` `pointIsOnLine(``int` `m, ``int` `c, ` `                          ``int` `x, ``int` `y) ` `{ ` `    ``// If (x, y) satisfies the equation  ` `    ``// of the line ` `    ``if` `(y == ((m * x) + c)) ` `        ``return` `true``; ` ` `  `    ``return` `false``; ` `} ` ` `  `// Driver code ` `public` `static` `void` `Main() ` `{ ` `    ``int` `m = 3, c = 2; ` `    ``int` `x = 1, y = 5; ` ` `  `    ``if` `(pointIsOnLine(m, c, x, y)) ` `        ``Console.Write(``"Yes"``); ` `    ``else` `        ``Console.Write(``"No"``); ` `} ` `} ` ` `  `// This code is contributed by Akanksha Rai `

## PHP

 ` `

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.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.

Article Tags :
Practice Tags :

3

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.