Write a program in C to check whether the given three points are collinear i.e. lie in same line or not

Write a program in C to check whether the given three points are collinear i.e. lie in same line or not.

            #include<stdio.h>
            #include<conio.h>
            #include<math.h>
            void main()
            {
                        int x1,y1,x2,y2,x3,y3;
                        int s1,s2,s3;
                        clrscr();
                        printf("Enter the value of x1 and y1 of first point:\n");
                        scanf("%d%d",&x1,&y1);
                        printf("Enter the value of x2 and y2 of second point:\n");
                        scanf("%d%d",&x2,&y2);
                        printf("Enter the value of x3 and y3 of third point:\n");
                        scanf("%d%d",&x3,&y3);
                        /*calculate slope of line between each pair of point*/
                        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("\nGiven points are collinear");
                        else
                                    printf("\nGiven points are NOT collinear");
                        printf("\nPress any key to exit...");
                        getch();
            }


Post a Comment