1 #include<iostream> 2 #include<cmath> 3 #include<iomanip> 4 using namespace std; 5 6 int main() 7 { 8 double a, b, c; 9 10 cout << "please enter a, b and c:"; 11 cin >> a >> b >> c; 12 13 if (a + b > c && b + c > a && c + a > b)//判断能否构成三角形 14 { 15 double s, area; 16 17 s = 0.5 * (a + b + c); 18 area = sqrt(s * (s-a) * (s-b) * (s-c)); 19 20 cout << setiosflags(ios::fixed) << setprecision(4); 21 cout << "area = " << area << endl; 22 } 23 else cout << "it is not a trilateral!" << endl; 24 while (1); 25 return 0; 26 }