C# program to find the maximum of three numbers


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!

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 19-Jun-2020

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements