The area of an arbitrary triangle-area of any triangle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.