沒指明用什麼語言, 用C寫了。
#include
int main(){
double x1, y1, x2, y2, x3, y3;
double k, b, t;
//輸入3個座標:
printf("Input point A:x, y:");
scanf("%lf, %lf", &x1, &y1);
printf("Input point b:x, y:");
scanf("%lf, %lf", &x2, &y2);
printf("Input point C:x, y:");
scanf("%lf, %lf", &x3, &y3);
k = (y2-y1)/(x2-x1);
b = y1-k*x1;
t = k*x3 + b;
if (fabs(y3-t)
printf("三點在一條直線上。\n");
else
printf("三點不在一條直線上。\n");
return 0;
}
沒指明用什麼語言, 用C寫了。
#include
#include
int main(){
double x1, y1, x2, y2, x3, y3;
double k, b, t;
//輸入3個座標:
printf("Input point A:x, y:");
scanf("%lf, %lf", &x1, &y1);
printf("Input point b:x, y:");
scanf("%lf, %lf", &x2, &y2);
printf("Input point C:x, y:");
scanf("%lf, %lf", &x3, &y3);
k = (y2-y1)/(x2-x1);
b = y1-k*x1;
t = k*x3 + b;
if (fabs(y3-t)
printf("三點在一條直線上。\n");
else
printf("三點不在一條直線上。\n");
return 0;
}