
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Maximum of Three Numbers in C#
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.
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!
Advertisements