#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
double x1,y1,x2,y2;
double d;
while(cin>>x1>>y1>>x2>>y2)
{
d=sqrt(pow((x1-x2),2)+pow(y1-y2,2));
cout<<fixed<<setprecision(2)<<d<<endl;
}
return 0;
}
以前学C++的时候没关注过小数点后的位数的问题
文件 <iomanip> io 分别是input和output manip 是manipulate 是操作的意思
在这个文件中含有一个叫做setprecision precision 是精度的意思 接下来有个例子
<pre class="cpp" name="code" style="margin-top: 0px; margin-bottom: 10px; font-size: 13px; background-color: rgb(255, 255, 255);">#include <iostream>
#include <iomanip>
using namespace std;
int main( void )
{
const double value = 12.3456789;
cout <