Q:

C# program to demonstrate example of conditional operator

0

C# program to demonstrate example of conditional operator

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C# example for conditional/ternary operator

Here, we are asking to input two numbers and finding the largest number.

// C# program to demonstrate example of 
// conditional operator
using System;
using System.IO;
using System.Text;

namespace IncludeHelp
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {
            //finding largest of two numbers 
            int a;
            int b;

            //input numbers 
            Console.Write("Enter first number : ");
            a = Convert.ToInt32(Console.ReadLine());
            Console.Write("Enter second number: ");
            b = Convert.ToInt32(Console.ReadLine());

            //finding largest number
            int large = (a > b) ? a : b;

            Console.WriteLine("Largest number is {0}", large);


            //hit ENTER to exit the program
            Console.ReadLine();
        }
    }
}

Output

Enter first number : 100
Enter second number: 200
Largest number is 200

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# program to demonstrate example of nested condit... >>
<< C# program to demonstrate example of nested if els...