CSharp - Write program to Get the Greater of Two Numbers

Requirements

You will write a program that asks the user for two numbers and then tells which of the two numbers is greater.

Demo

using System;
class Program/*from  w w w.  j a va  2 s  .  c o m*/
{
    static void Main(string[] args)
    {
        // Inputs 
        Console.Write("Enter first number: ");
        string input1 = Console.ReadLine();
        int number1 = Convert.ToInt32(input1);

        Console.Write("Enter second number: ");
        string input2 = Console.ReadLine();
        int number2 = Convert.ToInt32(input2);

        // Evaluating 
        int greater;
        if (number1 > number2)
        {
            greater = number1;
        }
        else
        {
            greater = number2;
        }

        // Output 
        Console.WriteLine("Greater of entered numbers is: " + greater);

    }
}

Result

The following code does the same check.

Demo

using System;
class Program//from w  ww  .  ja va 2 s. c  o  m
{
    static void Main(string[] args)
    {
        // Inputs 
        Console.Write("Enter first number: ");
        string input1 = Console.ReadLine();

        int number1 = Convert.ToInt32(input1);

        Console.Write("Enter second number: ");
        string input2 = Console.ReadLine();
        int number2 = Convert.ToInt32(input2);

        // Evaluating 
        int greater = number1;
        if (number2 > greater)
        {
            greater = number2;
        }

        // Output 
        Console.WriteLine("Greater of entered numbers is: " + greater);
    }
}

Result