In this program, we will discuss a simple concept of program to find the largest number among three numbers in the C# programming language.
In this topic, we learn how to find the biggest number from given three numbers. we can use the operator in C# language to find the biggest number of this program.
Using if statements to find the largest number
Among integer numbers
Program 1 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | class Program { static void Main(string[] args) { int num1, num2, num3; Console.WriteLine("Enter the first number to compare: "); num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the second number to compare: "); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the third number to compare: "); num3 = Convert.ToInt32(Console.ReadLine()); if (num1 >= num2 && num1 >= num3) { Console.WriteLine("\nLargest number is:" + num1); } if (num2 >= num1 && num2 >= num3) { Console.WriteLine("\nLargest number is:" + num2); } if (num3 >= num1 && num3 >= num2) { Console.WriteLine("\nLargest number is:" + num3); } Console.ReadLine(); } } |
Among floating point numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | class Program { static void Main(string[] args) { float num1, num2, num3; Console.WriteLine("Enter the first number to compare: "); num1 = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Enter the second number to compare: "); num2 = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Enter the third number to compare: "); num3 = Convert.ToSingle(Console.ReadLine()); if (num1 >= num2 && num1 >= num3) { Console.WriteLine("\nLargest number is:" + num1); } if (num2 >= num1 && num2 >= num3) { Console.WriteLine("\nLargest number is:" + num2); } if (num3 >= num1 && num3 >= num2) { Console.WriteLine("\nLargest number is:" + num3); } Console.ReadLine(); } } |
Using if -else statements to find the largest number
In this program, we will discuss a simple concept of program to find the largest number among three numbers in the C# programming language.
In this topic, we learn how to find the biggest number from given three numbers. we can use the operator in C# language to find the biggest number of this program.
Using if statements to find the largest number
Among integer numbers
Program 1 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | class Program { static void Main(string[] args) { int num1, num2, num3; Console.WriteLine("Enter the first number to compare: "); num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the second number to compare: "); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the third number to compare: "); num3 = Convert.ToInt32(Console.ReadLine()); if (num1 >= num2 && num1 >= num3) { Console.WriteLine("\nLargest number is:" + num1); } if (num2 >= num1 && num2 >= num3) { Console.WriteLine("\nLargest number is:" + num2); } if (num3 >= num1 && num3 >= num2) { Console.WriteLine("\nLargest number is:" + num3); } Console.ReadLine(); } } |
Among floating point numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | class Program { static void Main(string[] args) { float num1, num2, num3; Console.WriteLine("Enter the first number to compare: "); num1 = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Enter the second number to compare: "); num2 = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Enter the third number to compare: "); num3 = Convert.ToSingle(Console.ReadLine()); if (num1 >= num2 && num1 >= num3) { Console.WriteLine("\nLargest number is:" + num1); } if (num2 >= num1 && num2 >= num3) { Console.WriteLine("\nLargest number is:" + num2); } if (num3 >= num1 && num3 >= num2) { Console.WriteLine("\nLargest number is:" + num3); } Console.ReadLine(); } } |
Using if -else statements to find the largest number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | class Program { static void Main(string[] args) { float num1, num2, num3; Console.WriteLine("Enter the first number to compare: "); num1 = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Enter the second number to compare: "); num2 = Convert.ToSingle(Console.ReadLine()); Console.WriteLine("Enter the third number to compare: "); num3 = Convert.ToSingle(Console.ReadLine()); if (num1 >= num2 && num1 >= num3) { Console.WriteLine("\nLargest number is:" + num1); } else if (num2 >= num3) { Console.WriteLine("\nLargest number is:" + num2); } else { Console.WriteLine("\nLargest number is:" + num3); } Console.ReadLine(); } } |