Exercise
Greatest of three numbers
Objetive
Write a C# program that prompts the user to enter three numbers and displays the greatest one.
Example Code
using System;
class Program
{
static void Main()
{
double firstNumber, secondNumber, thirdNumber;
Console.Write("Enter the first number: ");
firstNumber = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the second number: ");
secondNumber = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the third number: ");
thirdNumber = Convert.ToDouble(Console.ReadLine());
if (firstNumber >= secondNumber && firstNumber >= thirdNumber)
{
Console.WriteLine("The greatest number is: {0}", firstNumber);
}
else if (secondNumber >= firstNumber && secondNumber >= thirdNumber)
{
Console.WriteLine("The greatest number is: {0}", secondNumber);
}
else
{
Console.WriteLine("The greatest number is: {0}", thirdNumber);
}
}
}