This program finds the greatest of the two numbers entered on the console screen:
The user enters two numbers by Console.ReadLine(). Console.ReadLine () reads the value of string type from the console. Then Convert.ToInt32 method converts the string value to int value. Finally if statement compares two numbers with greater operand
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
int number1, number2; Console.Write("Enter the First Number : "); number1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter the Second Number : "); number2 = Convert.ToInt32(Console.ReadLine()); if (number1 > number2) { Console.WriteLine("{0} is the Greater number then {1}", number1, number2); } else { Console.WriteLine("{0} is the Greater number then {1}", number2, number1); } Console.ReadLine(); |
Output:
Online Code: