Given two integer numbers and we have to find largest number using C# program.
Finding largest of two numbers
To find the largest number from given two numbers – we will compare their values using either the simple if-else statement or ternary operator. If the first number is greater than the second number, assign the first number to the variable in which we will store the largest number, if the first number is not the greater than the second number then assign the second number to the variable.
Let suppose given numbers are a and b and we have to store the largest number in large.
Syntax using if-else
if (a > b)
large = a;
else
large = b;
Syntax using ternary operator
large = (a > b) ? a : b;
C# code to find largest of two numbers
Here, we are asking for two integer numbers from the user and finding the largest one using if-else and ternary operator .
Output