C# program to read two numbers and find the maximum, minimum number

C# program to read two numbers and find maximum, minimum number

C# code to find minimum & minimum number:

// C# program to read two numbers 
// and find maximum, minimum number
using System;
using System.IO;
using System.Text;

namespace JustTechReview
{
    class Test
    {
        // Main Method 
        static void Main(string[] args)
        {
            int a;
            int b;
            int min;
            int max;

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

            //finding max number using if-else
            if (a > b)
                max = a;
            else
                max = b;

            //finding min number using if else
            if (a < b)
                min = a;
            else
                min = b;

            //printing
            Console.WriteLine("Using if-else...");
            Console.WriteLine("Minimum number = {0}", min);
            Console.WriteLine("Maximum number = {0}", max);

            //finding max number using ternary operator
            max = (a > b) ? a : b;

            //finding min number using ternary operator
            min = (a < b) ? a : b;

            //printing
            Console.WriteLine("Using Ternary operator...");
            Console.WriteLine("Minimum number = {0}", min);
            Console.WriteLine("Maximum number = {0}", max);

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

Output:

Enter first number : 100
Enter second number: 200
Using if-else...
Minimum number = 100
Maximum number = 200
Using Ternary operator...
Minimum number = 100
Maximum number = 200

Recent Posts

error: Alert: Content is protected!!