Created
October 15, 2014 10:36
-
-
Save IvanNikolov/acbeb5e510c51f3e8085 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
//Write a program that enters 3 real numbers and prints them | |
//sorted in descending order. Use nested if statements. | |
//Don’t use arrays and the built-in sorting functionality. | |
//Examples: | |
//a b c result | |
//5 1 2 5 2 1 | |
//-2 -2 1 1 -2 -2 | |
//-2 4 3 4 3 -2 | |
class Sort3NumbersUsingNestedIf | |
{ | |
static void Main() | |
{ | |
double a = double.Parse(Console.ReadLine()); | |
double b = double.Parse(Console.ReadLine()); | |
double c = double.Parse(Console.ReadLine()); | |
if (a > b && a > c) | |
{ | |
if (b > c) | |
{ | |
Console.WriteLine(a + " " + b + " " + c); | |
} | |
else | |
{ | |
Console.WriteLine(a + " " + c + " " + b); | |
} | |
} | |
else if (b > a && b > c) | |
{ | |
if (a > c) | |
{ | |
Console.WriteLine(b + " " + a + " " + c); | |
} | |
else | |
{ | |
Console.WriteLine(b + " " + c + " " + a); | |
} | |
} | |
else if (c > a && c > b) | |
{ | |
if (a >= b) | |
{ | |
Console.WriteLine(c + " " + a + " " + b); | |
} | |
else | |
{ | |
Console.WriteLine(c + " " + b + " " + a); | |
} | |
} | |
else if ((a == b && b == c) && (c == a)) | |
{ | |
Console.WriteLine(a + " " + b + " " + c); | |
} | |
//OPTION 2 | |
//double a = double.Parse(Console.ReadLine()); | |
//double b = double.Parse(Console.ReadLine()); | |
//double c = double.Parse(Console.ReadLine()); | |
//if ((a>b && a>c) && (b>c)) | |
//{ | |
// Console.WriteLine(a+" "+b+" "+c); | |
//} | |
//else if ((a>b && a>c) && (c>b)) | |
//{ | |
// Console.WriteLine(a+" "+c+" "+b); | |
//} | |
//else if ((b>a && b>c) && (a>c)) | |
//{ | |
// Console.WriteLine(b+" "+a+" "+c); | |
//} | |
//else if ((b>a && b>c) && (c>a)) | |
//{ | |
// Console.WriteLine(b+" "+c+" "+a); | |
//} | |
//else if ((c>a && c>b) && (a>= b)) | |
//{ | |
// Console.WriteLine(c+" "+a+" "+b); | |
//} | |
//else if ((c>a && c>b) && (b>=a)) | |
//{ | |
// Console.WriteLine(c+" "+b+" "+a); | |
//} | |
//else | |
//{ | |
// Console.WriteLine(a+" "+b+" "+c); | |
//} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment