在平面直角坐標系中求兩點的距離,
輸入
輸入有若干行,每行四個浮點數,分別代別兩個坐標點(a,b)和(c,d),
輸出
對于每組資料,對應輸出這兩點之間的距離,結果保留兩位小數,
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
#define PI 3.14159
struct point{
double a,b;
};
int main()
{
point x,y;
while(cin>>x.a>>x.b>>y.a>>y.b)
{
double distance;
distance=pow(x.a-y.a,2)+pow(x.b-y.b,2);
cout<<setiosflags(ios::fixed)<<setprecision(2)<<sqrt(distance)<<endl;
}
}
結構體設定點,math函式庫pow函式,sqrt函式輔助運算 ,然后用iomanip中進行輸出設定
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/243604.html
標籤:其他
上一篇:Android無限回圈滾動
下一篇:討論IOS開發以及自己的經驗
