#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,k,a1,a2,b1,b2,x[10],y[10];
clrscr();
printf("Enter Co-ordinates of point A as a1 and a2: ");
scanf("%d%d",&a1,&a2);
printf("Enter Co-ordinates of point B as b1 and b2: ");
scanf("%d%d",&b1,&b2);
printf("Enter number of points you want to sort: ");
scanf("%d",&n);
printf("Enter the Co-ordinates of n points: ");
for(i=0;i<n;i++)
scanf("%d%d",&x[i],&y[i]);
for(i=0;i<n;i++)
{
k=((b1-a1)*(y[i]-a2)-(b2-a2)*(x[i]-a1));
if(k>0)
printf("[%d %d] point is on the positive side of line AB.\n",x[i],y[i]);
else if(k<0)
printf("[%d %d] point is on the negative side of line AB.\n",x[i],y[i]);
else
printf("[%d %d] point is on the line AB.\n",x[i],y[i]);
}
getch();
}
//Output
Enter Co-ordinates of point A as a1 and a2: 3 3
Enter Co-ordinates of point B as b1 and b2: 7 7
Enter number of points you want to sort: 6
Enter the Co-ordinates of n points: 2 3
1 1
5 3
7 9
5 5
2 8
[2 3] point is on the positive side of line AB.
[1 1] point is on the line AB.
[5 3] point is on the negative side of line AB.
[7 9] point is on the positive side of line AB.
[5 5] point is on the line AB.
[2 8] point is on the positive side of line AB.
#include<conio.h>
void main()
{
int n,i,k,a1,a2,b1,b2,x[10],y[10];
clrscr();
printf("Enter Co-ordinates of point A as a1 and a2: ");
scanf("%d%d",&a1,&a2);
printf("Enter Co-ordinates of point B as b1 and b2: ");
scanf("%d%d",&b1,&b2);
printf("Enter number of points you want to sort: ");
scanf("%d",&n);
printf("Enter the Co-ordinates of n points: ");
for(i=0;i<n;i++)
scanf("%d%d",&x[i],&y[i]);
for(i=0;i<n;i++)
{
k=((b1-a1)*(y[i]-a2)-(b2-a2)*(x[i]-a1));
if(k>0)
printf("[%d %d] point is on the positive side of line AB.\n",x[i],y[i]);
else if(k<0)
printf("[%d %d] point is on the negative side of line AB.\n",x[i],y[i]);
else
printf("[%d %d] point is on the line AB.\n",x[i],y[i]);
}
getch();
}
//Output
Enter Co-ordinates of point A as a1 and a2: 3 3
Enter Co-ordinates of point B as b1 and b2: 7 7
Enter number of points you want to sort: 6
Enter the Co-ordinates of n points: 2 3
1 1
5 3
7 9
5 5
2 8
[2 3] point is on the positive side of line AB.
[1 1] point is on the line AB.
[5 3] point is on the negative side of line AB.
[7 9] point is on the positive side of line AB.
[5 5] point is on the line AB.
[2 8] point is on the positive side of line AB.
No comments:
Post a Comment