

為什么會這樣?哪里有錯誤?
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
float xa, ya, xb, yb, xc, yc, a, b, c, p, s;
cin >> xa >> ya >> xb >> yb >> xc >> yc;
a = sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya));
b = sqrt((xc-xb)*(xc-xb)+(yc-yb)*(yc-yb));
c = sqrt((xc-xa)*(xc-xa)+(yc-ya)*(yc-ya));
p = (a+b+c)/2;
s = sqrt(p*(p-a)*(p-b)*(p-c));
cout << fixed << setprecision(2);
cout << s;
}
uj5u.com熱心網友回復:
使用double代替floatuj5u.com熱心網友回復:
將float(單精)替換為double(雙精)#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
double xa, ya, xb, yb, xc, yc, a, b, c, p, s;
cin >> xa >> ya >> xb >> yb >> xc >> yc;
a = sqrt((xb-xa)*(xb-xa)+(yb-ya)*(yb-ya));
b = sqrt((xc-xb)*(xc-xb)+(yc-yb)*(yc-yb));
c = sqrt((xc-xa)*(xc-xa)+(yc-ya)*(yc-ya));
p = (a+b+c)/2;
s = sqrt(p*(p-a)*(p-b)*(p-c));
cout << fixed << setprecision(2);
cout << s;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/103053.html
標籤:C++ 語言
下一篇:客戶端連接不了服務器了
