## C Programming

### Check the points are co-linear or not

#### Objective:

Input coordinates for 3 points **(x1,y1)**, **(x2,y2)** and **(x3,y3)**. Write a program to check that all points are fall in one straight line or not.

#### Program / Solution:

#include<stdio.h> #include<math.h> int main() { int x1,y1,x2,y2,x3,y3; int s1,s2,s3; printf("Enter first point (x1,y1): "); scanf("%d%d",&x1,&y1); printf("Enter second point (x2,y2): "); scanf("%d%d",&x2,&y2); printf("Enter third point (x3,y3): "); scanf("%d%d",&x3,&y3); s1 = abs(x2 - x1) / abs(y2 - y1); //slop between point-1 and point-2 s2 = abs(x3 - x2) / abs(y3 - y2); //slop between point-2 and point-3 s3 = abs(x3 - x1) / abs(y3 - y1); //slop between point-3 and point-1 if((s1 == s2) && (s2 == s3)) { printf("Points are co-linear"); }else { printf("Points are not co-linear"); } return 0; }

#### Sample Output:

Enter first point (x1,y1): 1 1 Enter second point (x2,y2): 2 2 Enter third point (x3,y3): 3 3 Points are co-linear