Q:Given three points,write a program to check whether the given points fall in a straight line
#include
#include
void main()
{
int x1,x2,y1,y2,x3,y3;
int s1,s2,s3;
clrscr();
printf("enter value of x1,y1:");
scanf("%d%d",&x1,&y1);
printf("enter value of x2,y2:");
scanf("%d%d",&x2,&y2);
printf("enter value of x3,y3:");
scanf("%d%d",&x3,&y3);
s1=abs(x2-x1)/abs(y2-y1);
s2=abs(x3-x1)/abs(y3-y1);
s3=abs(x3-x2)/abs(y3-y2);
if(s1==s2&&s1==s3)
{
printf("points are collinear");
}
else
{
printf("points are not collonear");
}
getch();
}
7 comments:
what is abs in finding slope ?? will some one tell me please??
abs is absolute value function. I'm actually not sure why the programmer needed this. Additionally, this program may fail to give the right answer in certain cases, as the slopes are stored as integers.
Absolute cannot ensure correct results...!
what if y1-y2 or any other deno... is zero great;;;
what if y1-y2 or any other deno... is zero great;;;
Also done by -(area of triangle = 0)
What if the points lie on a horizontal line. It gives an divide error because points have the same y co-ordinates. So difference is zero and cannot be divided by zero.
Post a Comment