第 3 題 - 解答
#include <stdio.h>
#include <math.h>
int main()
{
double x1, y1, x2, y2, distance, slope;
printf("請輸入第1點座標(x1,y1):");
scanf("%lf,%lf",&x1,&y1);
printf("請輸入第2點座標(x2,y2):");
scanf("%lf,%lf",&x2,&y2);
distance=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
slope=(y2-y1)/(x2-x1);
printf("兩點的距離=%.2f\n",distance);
printf("兩點的斜率=%.2f\n",slope);
return 0;
}
考試版本
#include <stdio.h>
#include <math.h>
int main()
{
double x1, y1, x2, y2, distance, slope;
scanf("%lf,%lf",&x1,&y1);
scanf("%lf,%lf",&x2,&y2);
distance=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
slope=(y2-y1)/(x2-x1);
printf("%.2f\n",distance);
printf("%.2f\n",slope);
return 0;
}