Advertisement
hiker43

TriagnleArea

Aug 13th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. double triangleArea (double a, double b, double c)
  5. {
  6.     if (a+b>c && a+c>b && b+c>a)
  7.     {
  8.         double s=(a+b+c)/2;
  9.         return std::sqrt(s*(s-a)*(s-b)*(s-c));
  10.     }
  11.     else
  12.     {
  13.        return 0;
  14.     }
  15. }
  16.  
  17. int main()
  18. {
  19.        int a, b, c;
  20.        std::cout<<"Enter the sides of the triangle: \t";
  21.        std::cin>>a>>b>>c;
  22.        double P=triangleArea (a, b, c);
  23.        if (P==0)
  24.        {
  25.            std::cout<<"There is not a triangle with these sides";
  26.  
  27.        }
  28.        else
  29.        {
  30.            std::cout<<"Its area is: \t"<<P;
  31.        }
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement