用C语言代码完成输入两个点的坐标(x1,y1)、(x2,y2),编写一个计算这两点之间距离的程序。
时间: 2024-06-05 10:07:28 浏览: 19
好的,让我帮您解决这个问题。您可以参考以下代码:
#include <stdio.h>
#include <math.h>
int main()
{
float x1, y1, x2, y2, distance;
printf("Enter point 1 (x1, y1): ");
scanf("%f %f", &x1, &y1);
printf("Enter point 2 (x2, y2): ");
scanf("%f %f", &x2, &y2);
distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
printf("Distance between the two points is: %f", distance);
return 0;
}
这个程序会先让用户输入两个点的坐标,然后计算两点之间的距离,并输出结果。
相关问题
输入两个点的坐标(x1,y1)、(x2,y2),编写一个计算这两点之间距离的C语言程序
以下是计算两点之间距离的C语言程序:
```c
#include <stdio.h>
#include <math.h>
int main()
{
float x1, y1, x2, y2, distance;
printf("请输入第一个点的坐标(x1,y1): ");
scanf("%f,%f", &x1, &y1);
printf("请输入第二个点的坐标(x2,y2): ");
scanf("%f,%f", &x2, &y2);
distance = sqrt(pow((x2 - x1), 2) + pow((y2 - y1), 2));
printf("两点之间的距离为: %.2f", distance);
return 0;
}
```
运行程序后,先输入第一个点的坐标,再输入第二个点的坐标,程序会输出这两点之间的距离。注意输入坐标时,用逗号隔开。
要求从键盘输入两个点的坐标 x1、y1、x2、y2,然后输出它们之间的距离的C语言
以下是计算两个点之间距离的C语言程序:
```c
#include <stdio.h>
#include <math.h>
int main() {
double x1, y1, x2, y2, distance;
printf("Enter the coordinates of the first point (x1, y1): ");
scanf("%lf %lf", &x1, &y1);
printf("Enter the coordinates of the second point (x2, y2): ");
scanf("%lf %lf", &x2, &y2);
distance = sqrt(pow((x2-x1), 2) + pow((y2-y1), 2));
printf("The distance between the two points is: %lf\n", distance);
return 0;
}
```
程序要求用户输入两个点的坐标,然后使用数学库函数`sqrt()`和`pow()`计算两个点之间的距离,并输出结果。