早教吧作业答案频道 -->其他-->
c语言计算距离问题Problem Description输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离.Input输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开.Output对于每
题目详情
c语言计算距离问题
Problem Description
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离.
Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开.
Output
对于每组输入数据,输出一行,结果保留两位小数.
Sample Input
0 0 0 10 1 1 0
Sample Output
1.001.41
我自己写的代码
#include
#include"math.h"
int main()
{
int a,b,c,d;
float z;
while(scanf(" %d%d%d%d",&a,&b,&c,&d)!=EOF)
{
z=(c-a)*(c-a)+(d-b)*(d-b);
printf("%.2f\n",sqrt(z));
}
return 0;
}
提交时显示Output Limit Exceeded
Problem Description
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离.
Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开.
Output
对于每组输入数据,输出一行,结果保留两位小数.
Sample Input
0 0 0 10 1 1 0
Sample Output
1.001.41
我自己写的代码
#include
#include"math.h"
int main()
{
int a,b,c,d;
float z;
while(scanf(" %d%d%d%d",&a,&b,&c,&d)!=EOF)
{
z=(c-a)*(c-a)+(d-b)*(d-b);
printf("%.2f\n",sqrt(z));
}
return 0;
}
提交时显示Output Limit Exceeded
▼优质解答
答案和解析
#include
int main() {
int a,b,c,d;
double z;
while(scanf("%d%d%d%d",&a,&b,&c,&d) == 4) {
z=(c-a)*(c-a)+(d-b)*(d-b);
printf("%.2lf\n",sqrt(z));
}
return 0;
}
/*
1 4 8 0
8.06
1 2 3 4
2.83
q
Press any key to continue
*/
#include#include
int main() {
int a,b,c,d;
double z;
while(scanf("%d%d%d%d",&a,&b,&c,&d) == 4) {
z=(c-a)*(c-a)+(d-b)*(d-b);
printf("%.2lf\n",sqrt(z));
}
return 0;
}
看了 c语言计算距离问题Probl...的网友还看了以下:
输入输出接口是PNP、NPN型是什么意思,它和3极管PNP、NPN什么区别?我们说的输入输出接口是 2020-05-17 …
点P是矩形ABCD的边AD上的一个动点,矩形的两条边长AB、BC分别为8和15,求点P到矩形的两条 2020-05-20 …
表中民航运输客运量比重较小,但客运周转量比重较大,其原因是()A.航空运量较小,但平均运输距离较远 2020-07-15 …
如表为2011年我国各种交通运输方式货运量和客运量及周转量(运量与运输距离之积)比重表.阅读表格, 2020-07-19 …
如表为2011年我国各种交通运输方式货运量和客运量及周转量(运量与运输距离之积)比重表.阅读表格, 2020-07-19 …
有一块等边三角形的空地,小明和小亮想在这块空地上找到一点,使得这一点到三边的距离之和最短,他们做了 2020-08-03 …
交通运输业是经济发展的先行官,读运输价格和运输距离之间的关系图,判断下列叙述,错误的是()A.常见的 2020-12-04 …
如表为2011年我国各种交通运输方式货运量和客运量及周转量(运量与运输距离之积)比重表.阅读表格,完 2020-12-15 …
如表为2011年我国各种交通运输方式货运量和客运量及周转量(运量与运输距离之积)比重表.阅读表格,完 2020-12-15 …
一已知线段AB=5cm,在同一平面内讨论下列问题:(1)是否存在一点C,使它到A.B两点的距离之和最 2020-12-23 …