Advertisement

Latest Post

Sunday, 1 January 2017

How to find the greatest of three numbers [C#]

Write a program in C# to find the greatest of three numbers.

Following is the simple C# code :

class Lab
    {
        static void Main(string[] args)
        {

            int num1, num2, num3;
            Console.WriteLine("Enter Three number:");
            num1 = Convert.ToInt32(Console.ReadLine());
            num2 = Convert.ToInt32(Console.ReadLine());
            num3 = Convert.ToInt32(Console.ReadLine());
            if (num1 > num2)
                if (num1 > num3)
                {
                    Console.WriteLine("The Greatest Of Three numbers is:" + num1);
                }
                else
                {
                    Console.WriteLine("The Greatest Of Three numbers is:" + num3);
                }
            else
                if (num2 > num3)
                {
                    Console.WriteLine("The Greatest Of Three numbers is:" + num2);
                }
                else
                {
                    Console.WriteLine("The Greatest Of Three numbers is:" + num3);
                }
            Console.ReadLine();

        }
    }

Output:-

Government Jobs