三角形面積公式
阿新 • • 發佈:2018-01-27
please () cout iomanip col bsp ril esp set
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 }
三角形面積公式