Thursday, 15 October 2015

Maximum number among three numbers using ternary operator in C#

using System;
class Program
{
    public static void Main()
    {
        Console.WriteLine("Enter first Number");
        int FirstNumber = int.Parse(Console.ReadLine());
        Console.WriteLine("Enter second Number");
        int SecondNumber = int.Parse(Console.ReadLine());
        Console.WriteLine("Enter Third Number");
        int thirdNumber = int.Parse(Console.ReadLine());

        int maxNumber = (FirstNumber > SecondNumber)? (FirstNumber>thirdNumber ? FirstNumber : thirdNumber):(SecondNumber>thirdNumber?SecondNumber:thirdNumber);
        Console.WriteLine("Maximum Number among {0}, {1} and {2} is {3}",FirstNumber,SecondNumber,thirdNumber,maxNumber);
    }
}

No comments:

Post a Comment