Turbo C - Check whether given point lies on a Line (Y = MX + C)
Here is the Turbo C program to check whether given point lies on a line or not.
We directly got the equation for the two lines Y = MX + C as input
Where M = Slope of a Line and C = Intercept
Solve the given point px and py with Y = MX + C.
NOTE: To check the given point lies on a line segment, click here
Source Code
#include <stdio.h>
#include <math.h>
void main()
{
float slope, intercept;
float px, py;
printf("Program to find whether the given point lies on a line:\n");
printf("Enter Line1 - Slope: ");
scanf("%f", &slope);
printf("Enter Line1 - Intercept: ");
scanf("%f", &intercept);
printf("Enter Point X: ");
scanf("%f", &px);
printf("Enter Point Y: ");
scanf("%f", &py);
printf("Equation of the line: ");
printf("%.2fX %c %.2f\n", slope, ((intercept < 0) ? ' ' : '+'), intercept);
if( slope * px + intercept > (py - 0.01) &&
slope * px + intercept < (py + 0.01))
{
printf("Given point lies on the line\n");
}
else
printf("Given point is outside the line\n");
}
Output
Program to find whether the given point lies on a line:
Enter Line1 - Slope: 1.25
Enter Line1 - Intercept: 0.75
Enter Point X: 2.33
Enter Point Y: 3.67
Equation of the line: 1.25X +0.75
Given point lies on the line
Press any key to continue . . .
|