<< Home | <<C Programs Home



c programs to check given three points are collinear or not.

Page<< C Programs Home
Page<< C Programs Home
  

C Program :

Given coordinates of three points (x1,y1), (x2,y2) & (x3,y3). Write a prog. to check if they are collinear.

C Programming -->

/* PROG. TO CHECK GIVEN THREE POINTS ARE COLLINEAR OR NOT */ #include<stdio.h> #include<conio.h> #include<math.h> main() { int x1,x2,x3,y1,y2,y3; float d1,d2,d3; int cl,c2,C3; clrscr(); printf("enter coordinates ofthree points"); scanf("%d%d%d%d%d%d" ,&x 1,&yl ,&x2,&y2,&x3,&y3); /* calculate distance between two points */ d1= sqrt( (x1-x2)*(x1-x2) + (yl-y2)*(yl-y2)); d2= sqrt( (x3-x2)*(x3-x2) + (y3-y2)*(y3-y2) ); d3= sqrt( (xl-x3)*(x1-x3) + (y1-y3)*(y1-y3)); /* check the conditions */ cl = ( d1+d2=d3 ); c2= (d2+d3=dl ); c3= (d3+dl==d2); if(c 111c211c3) printf(" points are collinear"); else printf("points are not collinear"); getch(); }
Page<< C Programs Home



 
Copyright © 2006-2012 ExamBlast.com Last Updated 08-April-2012