基础题。
C语言版
#include<stdio.h>
#include<math.h>
int main()
{
double x1, y1, x2, y2, p, f;
while(scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2) == 4)
{
p = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
f = sqrt(p);
printf("%.2lf\n",f);
}
return 0;
}
C++中小数的输入输出
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
double x1, y1, x2, y2, p1, p2, t, f;
while(cin >> x1 >> y1 >> x2 >> y2)
{
p1 = (x2 - x1) * (x2 - x1);
p2 = (y2 - y1) * (y2 - y1);
t = p1 + p2;
f = sqrt(t);
cout.setf(ios::fixed);
cout << setprecision(2) << f << endl;
}
return 0;
}