Blogger Widgets


C# Program to check all the three points fall on one straight line or not
Program to check all the three points fall on one straight line or not

Program Statement: 
Write a program which takes three points (x1, y1), (x2, y2) and (x3, y3) from user and program will check if all the three points fall on one straight line or not.

Solution:

 static void Main(string[] args)
{
double x1, x2, x3, y1, y2, y3, m1, m2;
Console.WriteLine("Enter value of x1");
x1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value of x2");
x2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value of x3");
x3 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value of y1");
y1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value of y2");
y2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter value of 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 to 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 on one straight line.\ n\n"); }
else
{ Console.WriteLine("\n\t\tSo Given point does not fall on one straig ht line.\n\n"); }
}
}

C# Program to check all the three points fall on one straight line or not
29 Nov 2013

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Top