这道题本身不难的,主要用于练习C++的cout格式化输出
#include <iostream> #include <iomanip> #include<string.h> #include<math.h> using namespace std; double x11,y11,x22,y22; double calculate(double x1,double y1,double x2,double y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } int main() { cout.setf(ios::fixed); while(cin>>x11>>y11>>x22>>y22){ double k=calculate(x11,y11,x22,y22); cout<<setprecision(2)<<k<<endl; } return 0; }