hdu_problem_2001_計算兩點間的距離
阿新 • • 發佈:2019-01-10
/*
*
*Problem Description
*輸入兩點座標(X1,Y1),(X2,Y2),計算並輸出兩點間的距離。
*
*
*Input
*輸入資料有多組,每組佔一行,由4個實陣列成,分別表示x1,y1,x2,y2,資料之間用空格隔開。
*
*
*Output
*對於每組輸入資料,輸出一行,結果保留兩位小數。
*
*
*Sample Input
*0 0 0 1
*0 1 1 0
*
*
*Sample Output
*1.00
*1.41
*
*
*Author
*lcy
*
*
*Source
*C語言程式設計練習(一)
*
*
*Recommend
*JGShining
*
*/ #include<iostream>
using namespace std;
float distance(float x1, float y1, float x2, float y2) {
return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
float sqrt(int num) {
float temp;
for (temp = 0; temp*temp <= num; temp+=1);
temp-=1;
for (int i = 0; i < 3; i++) {
temp = (temp + num / temp) / 2;
}
return temp;
}
int main() {
float x1, y1, x2, y2;
while (cin >> x1 >> y1 >> x2 >> y2) {
printf("%.2f\n", distance(x1,y1,x2,y2));
}
system("pause");
return 0;
}