Given number are Pythagorean Triplet

Three numbers can be said as Pythagorean Triplet when a>b>c and a2 + b2 = c2.


Write a program to determine the given numbers set of Pythagorean Triplet

Solution:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pythagorean
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Enter a number:");
            var num1 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter a number:");
            var num2 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter a number:");
            var num3 = Convert.ToInt32(Console.ReadLine());

            if (num1 > num2 || num2 > num3)
            {
                Console.WriteLine("Not a Pythagorean Triplet");
            }
            else
            {
                Console.WriteLine((num1*num1) + (num2* num2) == (num3* num3)
                    ? "Pythagorean Triplet"
                    : "Not a Pythagorean Triplet");
            }

            Console.ReadLine();
        }

    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *