Wednesday 20 January 2016

Points in a line (Solution to week 1 Assignment)

Given three points (x1, y1), (x2, y2) and (x3, y3) , write a program to check if all the three points fall on one straight line.


INPUT: Six integers x1, y1, x2, y2, x3, y3 separated by whitespace.


OUTPUT: Print “Yes” if all the points fall on straight line, “No” otherwise.


CONSTRAINTS:

-1000 <= x1, y1, x2, y2, x3, y3 <= 1000

Solution -:

#include<stdio.h>

int main()
{int x1,x2,x3,y1,y2,y3;

 float d;
  scanf("%d%d",&x1,&y1);
  scanf("%d%d",&x2,&y2);
  scanf("%d%d",&x3,&y3);
  
 d= (x1*(y2-y3) + x2*(y3-y1) +x3*(y1-y2));
  
  if(d==0)
    printf("Yes");
  else
    printf("No");
return 0;
}

No comments:

Post a Comment