Question-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.
Solution= it's again a basic problem. just you need to know the concept of same slope, which is given by "if every possible slopes are equal , points lie on the straight line." slope is given for points (x1,y1) and (x2,y2) by the formula m=(y2-y1)/(x2-x1);
let's see the solution .
#include<stdio.h>
int main()
{
int x1,y1,x2,y2,x3,y3,m1,m2; /* we can take float as well */
printf("Enter all the points(x,y format)\n");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
m1=(y2-y1)/(x2-x1);
m2=(y3-y2)/(x3-x2);
if(m1==m2)
printf("All the points are co-linear\n");
else
printf("They are not on the same line\n");
return 0;
}
program to check if all the three points fall on one straight line.
Solution= it's again a basic problem. just you need to know the concept of same slope, which is given by "if every possible slopes are equal , points lie on the straight line." slope is given for points (x1,y1) and (x2,y2) by the formula m=(y2-y1)/(x2-x1);
let's see the solution .
#include<stdio.h>
int main()
{
int x1,y1,x2,y2,x3,y3,m1,m2; /* we can take float as well */
printf("Enter all the points(x,y format)\n");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
m1=(y2-y1)/(x2-x1);
m2=(y3-y2)/(x3-x2);
if(m1==m2)
printf("All the points are co-linear\n");
else
printf("They are not on the same line\n");
return 0;
}
No comments:
Post a Comment