static void Main(string[] args) { var triangle = new Triangle(6, 8, 10); Console.WriteLine(triangle.CanTriangleExist()); Console.WriteLine(triangle.GetSquare()); Console.ReadLine(); }
/// <summary> /// Checks whether such triangle can exist /// </summary> /// <param name="triangle">Triangle to check</param> /// <returns></returns> public static bool CanTriangleExist(Triangle triangle) { if (triangle.SideA + triangle.SideB <= triangle.SideC) { return false; } if (triangle.SideA + triangle.SideC <= triangle.SideB) { return false; } if (triangle.SideB + triangle.SideC <= triangle.SideA) { return false; } return true; }
/// <summary> /// Calculates square of the triangle /// </summary> /// <param name="triangle">Triangle to calculate</param> /// <returns></returns> public static double GetSquare(Triangle triangle) { double p = triangle.Perimeter/2; return Sqrt(p*(p - triangle.SideA)*(p - triangle.SideB)*(p - triangle.SideC)); }