Program toward check all the three points fall at one straight line or notProgram Statement: Write a program which takes three points (x1, y1), (x2, y2) furthermore (x3, y3) from user furthermore program will check if all the three points fall at one straight line or not.
Solution:
static void Main(string[] args)
{
double x1, x2, x3, y1, y2, y3, m1, m2;
Console.WriteLine("Enter value regarding x1");
x1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value regarding x2");
x2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value regarding x3");
x3 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value regarding y1");
y1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value regarding y2");
y2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value regarding y3");
y3 = Convert.ToInt32(Console.ReadLine());
m1 = (x2 - x1) / (y2 - y1);
m2 = (x3 - x2) / (y3 - y2);
if (x2 - x1 == 0 || x3 - x2 == 0)
{ Console.WriteLine("\t\tInvalid input (Attempted toward divide by zero)!");}
else
{
m1 = (y2 - y1) / (x2 - x1);
m2 = (y3 - y2) / (x3 - x2);
Console.WriteLine("\t\tSlope 1 = {0}", m1);
Console.WriteLine("\t\tSlope 2 = {0}", m2);
if (m1 == m2)
{ Console.WriteLine("\n\t\tSo Given point fall at one straight line.\ n\n"); }
else
{ Console.WriteLine("\n\t\tSo Given point does not fall at one straig ht line.\n\n"); }
}
}