C# Program to Find a Number using Pythagoras Theorem

In geometry, Pythagoras theorem is used to find the length of the hypotenuse of a right-angled triangle. In this task, we will write a C# program to find a number using Pythagoras theorem.

Problem Statement

Write a C# program to find a number using Pythagoras theorem. The program should take input from the user in the form of the length of the two sides of a right-angled triangle. The program should display the length of the hypotenuse as output.

C# Program to Find a Number using Pythagoras Theorem

using System;

class Program
{
    static void Main(string[] args)
    {
        double a, b, c;
        Console.WriteLine("Enter the First Value ");
        a = double.Parse(Console.ReadLine());
        Console.WriteLine("Enter the Second Value ");
        b = double.Parse(Console.ReadLine());
        c = Math.Sqrt(a * a + b * b);
        Console.WriteLine("The Other Number is : {0}", c);
        Console.ReadLine();
    }
}

Input / Output

C# Program to Find a Number using Pythagoras Theorem

Share:

Leave A Reply

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...