Calculate the distance between two points of the problem

#include <iostream>
#include<math.h> #include<iomanip> using namespace std; int main() { float i=0,a,b,c,d; float m; for(i=0;cin>>a>>b>>c>>d;i++) { m=sqrt((a-c)*(a-c)+(b-d)*(b-d)); //printf("%.2f\n",m); cout<<setprecision(2)<<fixed<<(sqrt((pow(a-c,2))+(pow(b-d,2))))<<endl; } } 

 

 First: pay attention to the input data if the floating-point type, which is relatively easy to overlook
second: c ++ inside setprecision can achieve control of the output digit numbers, but not zero output at the end of the decimal, and there is rounding, the header file is # include
achieve control output fixed number of digits after the decimal point and setprecision binding: third

Guess you like

Origin www.cnblogs.com/ZJK132/p/12283609.html