Saturday, July 19, 2014

C#: Enter the three numbers. Check to see that there is 3 sides of a triangle are not. If that is right, then see what kind of triangle.

//Enter the number 3. Check to see that there is 3 sides of a triangle are not. If that is right, then see what kind of triangle.
Source code:
class Program{
        static void Main() {
            float x, y, z;
            Console.Write("Input x: ");
            x = float.Parse(Console.ReadLine());
            Console.Write("Input y: ");
            y = float.Parse(Console.ReadLine());
            Console.Write("Input z: ");
            z = float.Parse(Console.ReadLine());
            if (x <= 0 || y <= 0 || z <= 0 || x + y <= z || y + z <= x || x + z <= y)
                Console.WriteLine("Input wrong !");
            else {
                if ((x == y && x * x * 2 == z * z) || (x == z && x * x * 2 == y * y) || (y == z && y * y * 2 == x * x))
                    Console.WriteLine("Triangle Square Scales");
                else {
                    if (x == y && y == z && z == x)
                        Console.WriteLine("Equilateral triangle");
                    else {
                        if (x == y || y == z || z == x)
                            Console.WriteLine("Isosceles triangle");
                        else
                            Console.WriteLine("Triangle");
                    }
                }
            }
            Console.ReadLine();
        }
}

No comments:

Post a Comment