Author : Rahul
Write a program to find the largest number between 3 numbers.
Program
using System;
namespace ProgrammingQuestion
{
class Program
{
static void Main(string[] args)
{
//Variable Declaration
string firstNumberVal,secondNumberVal, thirdNumberVal, message;
int firstNumber, secondNumber, thirdNumber;
//User Input
Console.Write("Enter First Number:");
firstNumberVal = Console.ReadLine();
firstNumber = Convert.ToInt32(firstNumberVal);
Console.Write("Enter Second Number:");
secondNumberVal = Console.ReadLine();
secondNumber = Convert.ToInt32(secondNumberVal);
Console.Write("Enter Third Number:");
thirdNumberVal = Console.ReadLine();
thirdNumber = Convert.ToInt32(thirdNumberVal);
//Greater Number Logic
if(firstNumber > secondNumber && firstNumber > thirdNumber)
{
message = $"Number {firstNumber} is greater.";
}
else if(secondNumber > firstNumber && secondNumber > thirdNumber)
{
message = $"Number {secondNumber} is greater.";
}
else if(thirdNumber > firstNumber && thirdNumber > secondNumber)
{
message = $"Number {thirdNumber} is greater.";
}
else
{
message = $"No Number is greater.";
}
//Print Result
Console.WriteLine(message);
Console.Read();
}
}
}
Output
Enter First Number:10
Enter Second Number:20
Enter Third Number:15
Number 20 is greater.