C# Program to Read Two Numbers and Find Maximum and Minimum Number

This article is a very important article. I mean in this C# Program to Read Two Numbers and Find Maximum and Minimum Number we are going to know very clearly about this. We hope you like this article. Please comment if you liked this article.

C# Program to Read Two Numbers and Find Maximum and Minimum Number

C# Program to Read Two Numbers and Find Maximum and Minimum Number

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

namespace IncludeHelp
{
    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();
        }
    }
}
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

Final Words

C# Program to Read Two Numbers and Find Maximum and Minimum Number We have clearly identified the information you need through the article. If in doubt please let us know your doubts via the comment box Thank you.

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment