等腰三角形的面积

来源:互联网 发布:ui和美工的区别 编辑:程序博客网 时间:2024/04/29 11:18
#include <iostream>#include <stdexcept>#include <cmath>#include<iomanip>using namespace std;/*完善此函数*/double calArea(double a, double b, double c) {if (a <= 0 || b <= 0 || c <= 0)throw invalid_argument("The input is illegal");if (a + b <= c || b + c <= a || c + a <= b)throw invalid_argument("The input is illegal");if (a != b && a != c && b != c)throw invalid_argument("The input is illegal");else{double p = (a + b + c) / 2;return  sqrt(p*(p - a)*(p - b)*(p - c));}}int main(){double a, b, c;cin >> a >> b >> c;try{double area = calArea(a, b, c);cout << fixed << setprecision(2) << area << endl;}catch (exception e){cout << e.what() << endl;}}

0 0
原创粉丝点击