Sunday, September 9, 2018

17. WAP to check if the points (x1,y1), (x2,y2) and (x3,y3) are collinear or not.

#include<stdio.h>
#include<conio.h>
void main()
{
   int x1,y1,x2,y2,x3,y3,value;
   printf("Enter the X co-ordinate of the First Point: ");
   scanf("%d",&x1);
   printf("Enter the Y co-ordinate of the First Point: ");
   scanf("%d",&y1);
   printf("\nEnter the X co-ordinate of the Second Point: ");
   scanf("%d",&x2);
   printf("Enter the Y co-ordinate of the Second Point: ");
   scanf("%d",&y2);
   printf("\nEnter the X co-ordinate of the Third Point: ");
   scanf("%d",&x3);
   printf("Enter the Y co-ordinate of the Third Point: ");
   scanf("%d",&y3);
   value = x1 * (y2-y3)
            + x2 * (y3-y1)
            + x3 * (y1-y2);
   if(value == 0)
printf("\nPoints are Collinear.");
   else
    printf("\nPoint are Non Collinear.");
   getch();

}


Output:






Please have a look at the below lesson posted on my YouTube channel:

No comments:

Post a Comment