Skip to content

Instantly share code, notes, and snippets.

@Brianceasar
Created November 30, 2022 06:34
Show Gist options
  • Save Brianceasar/7364699bf06c04b4475c945a72b25f3c to your computer and use it in GitHub Desktop.
Save Brianceasar/7364699bf06c04b4475c945a72b25f3c to your computer and use it in GitHub Desktop.
A program that sorts 3 real numbers in descending order using nested if-statement
class Program
{
static void Main(string[] args)
{
Console.Write("Enter first number: ");
int a = Int32.Parse(Console.ReadLine());
Console.Write("Enter second number: ");
int b = Int32.Parse(Console.ReadLine());
Console.Write("Enter third number: ");
int c = Int32.Parse(Console.ReadLine());
if (a < b)
{
if (a < c)
{
a = a + c;
c = a - c;
a = a - c;
if (b > c)
{
a = a + b;
b = a - b;
a = a - b;
}
}
else if (a >= c)
{
a = a + b;
b = a - b;
a = a - b;
}
}
else if (a == b)
{
if (a < c)
{
a = a + c;
c = a - c;
a = a - c;
}
}
else
{
if (b < c)
{
b = b + c;
c = b - c;
b = b - c;
}
if (a < b)
{
a = a + b;
b = a - b;
a = a - b;
}
}
Console.WriteLine("{0}, {1}, {2}", a, b, c);
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment