C# program to find largest of three numbers

 Algorithm:-

(1)start

(2)take three number from user and store in three variable a,b,c

(3)if a is greate than b and a is greate than c print first number is largest

(4)else if b is greate than a and b is greate than c print second number is largest

(5)else if c is greater than a and cis greater than b third number is greatest

(6)else print all numbers are equal

(7)stop


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace TestApplicationOnly

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                int num1, num2, num3;

                Console.Write("Input the 1st number :");

                num1 = Convert.ToInt32(Console.ReadLine());

                Console.Write("Input the  2nd number :");

                num2 = Convert.ToInt32(Console.ReadLine());

                Console.Write("Input the 3rd  number :");

                num3 = Convert.ToInt32(Console.ReadLine());

                if (num1 > num2 && num1 > num3)

                {

                    Console.Write("The 1st Number is the largest");

                }

                else if (num2 > num1 && num2 > num3)

                {

                    Console.Write("The 2nd Number is the largest");

                }

                else if (num3 > num1 && num3 > num2)

                {

                    Console.Write("The 3rd Number is the largest");

                }

                else

                {

                    Console.Write("All numbers are equal");

                }

            }

            catch (Exception ex)

            {

                Console.WriteLine("input is not in correct formate");

            }

            Console.ReadKey();  


        }

    }

}

output:-

Input the 1st number :2

Input the  2nd number :6

Input the 3rd  number :9

The 3rd Number is the largest

एक टिप्पणी भेजें

0 टिप्पणियाँ