The area of an arbitrary triangle-the area of any triangle, allows repeated calculation:
// The area of an arbitrary triangle-area of any triangle # include <iostream> # include <cmath> using namespace STD; bool istriangle (double A, double B, double C ); void areafun (double A, double B, double C, double & area, double & S); int main () {double A, B, C, S, area; char ans; do {cout <"Enter the three length of the triangle: \ n"; CIN> A> B> C; If (istriangle (A, B, C )) areafun (a, B, c, area, S); else cout <"The Three length are error! \ N "; cout <" do you want again? "; CIN> ans;} while ('y' = ans | 'y' = ans); Return 0;} bool istriangle (double A, double B, double C) {If (a + B> C & A + C> B & B + C> A & ABS (a-B) <C & ABS (a-c) <B & ABS (B-c) <a) return 1; return 0;} void areafun (double A, double B, double C, double & area, double & S) {S = (A + B + C)/2; Area = SQRT (S * (S-) * (S-B) * (s-c); cout <"The area of the triangle is:" <area <Endl ;}
Result:
Enter the three length of the triangle: 3 4 5The area of the triangle is: 6do you want again? Yenter the three length of the triangle: 3 4 4The area of the triangle is: 5.56215do you want again? Yenter the three length of the triangle: 3 4 9The three length are error! Do you want again? Yenter the three length of the triangle: 4 4 4The area of the triangle is: 6.9282do you want again?
The area of an arbitrary triangle-area of any triangle