C# Sharp exercises: Find the largest of three numbers
C# Sharp Conditional Statement : Exercise-8 with Solution
Write a C program to find the largest of three numbers.
Sample Solution:-
C# Sharp Code:
using System;
public class Exercise8
{
public static void Main()
{
int num1, num2, num3;
Console.Write("\n\n");
Console.Write("Find the largest of three numbers:\n");
Console.Write("------------------------------------");
Console.Write("\n\n");
Console.Write("Input the 1st number :");
num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the 2nd number :");
num2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the 3rd number :");
num3 = Convert.ToInt32(Console.ReadLine());
if (num1 > num2)
{
if (num1 > num3)
{
Console.Write("The 1st Number is the greatest among three. \n\n");
}
else
{
Console.Write("The 3rd Number is the greatest among three. \n\n");
}
}
else if (num2 > num3)
Console.Write("The 2nd Number is the greatest among three \n\n");
else
Console.Write("The 3rd Number is the greatest among three \n\n");
}
}
Sample Output:
Find the largest of three numbers: ------------------------------------ Input the 1st number :20 Input the 2nd number :25 Input the 3rd number :15 The 2nd Number is the greatest among three
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a C# Sharp program to accept the height of a person in centimeter and categorize the person according to their height.
Next: Write a C program to accept a coordinate point in an XY coordinate system and determine in which quadrant the coordinate point lies.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework