# C# program to find the maximum of three numbers

CsharpServer Side ProgrammingProgramming

#### Complete Python Prime Pack

9 Courses     2 eBooks

#### Artificial Intelligence & Machine Learning Prime Pack

6 Courses     1 eBooks

#### Java Prime Pack

9 Courses     2 eBooks

Firstly, let’s set the three numbers −

int num1, num2, num3;
// set the value of the three numbers
num1 = 10;
num2 = 20;
num3 = 50;

Now check the first number with the second number. If num1 > num2, then check num1 with num3. If num1 is greater than num3, that would mean the largest number is num1.

## Example

You can try to run the following code to find the maximum of three numbers.

Live Demo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class MyApplication {
static void Main(string[] args) {
int num1, num2, num3;
// set the value of the three numbers
num1 = 10;
num2 = 20;
num3 = 50;
if (num1 > num2) {
if (num1 > num3) {
Console.Write("Number one is the largest!");
} else {
Console.Write("Number three is the largest!");
}
}
else if (num2 > num3)
Console.Write("Number two is the largest!");
else
Console.Write("Number three is the largest!");
}
}
}

## Output

Number three is the largest!
Updated on 19-Jun-2020 11:38:44