📜  检查点(x,y)是否在给定线上

📅  最后修改于: 2021-04-29 17:10:21             🧑  作者: Mango

给定直线y =(m * x)+ c的方程的mc值,任务是确定点(x,y)是否位于给定线上。

例子:

方法:为了使给定点位于直线上,它必须满足直线方程。检查y =(m * x)+ c是否成立。

下面是上述方法的实现:

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


输出:
Yes