- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find minimum between 2 numbers using C#?
Firstly, declare and initialize two numbers.
int num1 = 35; int num2 = 55;
With that, use if- else to find the minimum number.
if (num1 < num2) { minNum = num1; } else { minNum = num2; }
Above, we have set the minimum value to the variable minNum and printed it later on.
The following is the complete example to find minimum between 2 numbers in C#.
Example
using System; namespace Demo { class Program { static void Main(string[] args) { int num1 = 50; int num2 = 90; int minNum; Console.WriteLine("Number 1: "+num1); Console.WriteLine("Number 2: "+num2); if (num1 < num2) { minNum = num1; } else { minNum = num2; } Console.WriteLine("Minimum number is: "+minNum); Console.ReadKey() ; } } }
Output
Number 1: 50 Number 2: 90 Minimum number is: 50
Advertisements