C# program to find largest number from given 3 numbers
Following program shows you how to find largest number from given 3 numbers.
In this program we get inputs from user and shows largest number from given three numbers using if condition
using System;
class MainClass {
public static void Main (string[] args) {
Console.WriteLine("Enter three numbers:");
int input1 = Convert.ToInt32 (Console.ReadLine());
int input2 = Convert.ToInt32(Console.ReadLine());
int input3 = Convert.ToInt32(Console.ReadLine());
if ((input1 == input2) && (input1 == input3)) {
Console.WriteLine ("All numbers are equal");
} else if ((input1 > input2) && (input1 > input3)) {
Console.WriteLine (input2 + " is larger than " + input1 + " and " + input3);
} else if ((input3 > input1) && (input3 > input2)) {
Console.WriteLine (input3 + " is larger than " + input2 + " and " + input1);
}
}
}
Output:
Example1:
Enter three numbers:
5
5
5
All numbers are equal
Example2:
Enter three numbers:
2
4
6
6 is larger than 4 and 2