C# Program to find the largest of three numbers using nested if
In this program, You will learn how to find the largest of three numbers using nested if statement in C#.
33 44 10 => 44
33 55 20 => 55
Example: How to find the largest of three numbers using nested if in C#.
using System;
public class Test
{
public static void Main(string[] args)
{
int x, y, z;
Console.Write("Enter first number:");
x = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number:");
y = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter third number:");
z = Convert.ToInt32(Console.ReadLine());
if (x > y)
{
if (x > z)
{
Console.WriteLine("Greatest is:" + x);
}
else
{
Console.WriteLine("Greatest is:" + z);
}
}
else
{
if (y > z)
{
Console.WriteLine("Greatest is:" + y);
}
else
{
Console.WriteLine("Greatest is:" + z);
}
}
}
}
Output:
Enter first number:10
Enter second number:30
Enter third number:20
Greatest is:30