C# Program to find the largest of three characters using nested if


In this program, You will learn how to find the largest of three characters using nested if statement in C#.


a b c => c

A B C => C

Example: How to find the largest of three characters using nested if in C#.

using System;
public class Test
{
	public static void Main(string[] args)
	{
		char x, y, z;
		Console.Write("Enter first character:");
		x = Convert.ToChar(Console.ReadLine());

		Console.Write("Enter second character:");
		y = Convert.ToChar(Console.ReadLine());

		Console.Write("Enter third character:");
		z = Convert.ToChar(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 character:d
Enter second character:a
Enter third character:c
Greatest is:d