[Homework] C#Basics - Conditional Statements . Problem {7} sort 3 numbers with Nested Ifs
Здравейте ,
Някой ще ми помогне ли със задача 4ри ,тъй като единствения начин ,по който за момента се сетих да я реша е това (малко по долу) ,а съм сигурен ,че има алгоритъм или една идея по-лесен начин за решението ѝ вместо да се редят сумати логически оператори ..
Благодаря предварително ! :)
using System;
class SortNumbers
{
static void Main()
{
Console.Write("Enter the fist number : ");
double numberOne = double.Parse(Console.ReadLine());
Console.Write("\nEnter the second number : ");
double numberTwo = double.Parse(Console.ReadLine());
Console.Write("\nEnter the third number : ");
double numberThree = double.Parse(Console.ReadLine());
if (numberOne < numberTwo && numberTwo < numberThree)
{
double temp = numberOne;
numberOne = numberThree;
numberThree = temp;
temp = numberTwo;
Console.WriteLine("Number one : {0} \nNumber two : {1} \nNumber three : {2} ", numberOne, numberTwo, numberThree);
}
else if (numberOne < numberThree && numberThree < numberTwo)
{
double temp = numberOne;
numberOne = numberTwo;
numberTwo = numberThree;
numberThree = temp;
Console.WriteLine("Number one : {0} \nNumber two : {1} \nNumber three : {2} ", numberOne, numberTwo, numberThree);
}
else if (numberTwo < numberThree && numberThree < numberOne)
{
double temp = numberTwo;
numberTwo = numberThree;
numberThree = temp;
Console.WriteLine("Number one : {0} \nNumber two : {1} \nNumber three : {2} ", numberOne, numberTwo, numberThree);
}
else if (numberTwo < numberOne && numberOne < numberThree)
{
double temp = numberTwo;
numberTwo = numberOne;
numberOne = numberThree;
numberThree = temp;
Console.WriteLine("Number one : {0} \nNumber two : {1} \nNumber three : {2} ", numberOne, numberTwo, numberThree);
}
else if (numberThree < numberOne && numberOne < numberTwo)
{
double temp = numberOne;
numberOne = numberTwo;
numberTwo = temp;
Console.WriteLine("Number one : {0} \nNumber two : {1} \nNumber three : {2} ", numberOne, numberTwo, numberThree);
}
else if (numberOne == numberTwo && numberTwo < numberThree)
{
numberOne = numberThree;
numberThree = numberTwo;
Console.WriteLine("Number one : {0} \nNumber two : {1} \nNumber three : {2} ", numberOne, numberTwo, numberThree);
}
else if (numberOne == numberThree && numberThree < numberTwo)
{
numberOne = numberTwo;
numberTwo = numberThree;
Console.WriteLine("Number one : {0} \nNumber two : {1} \nNumber three : {2} ", numberOne, numberTwo, numberThree);
}
else if (numberThree == numberTwo && numberTwo < numberOne)
{
Console.WriteLine("Number one : {0} \nNumber two : {1} \nNumber three : {2} ", numberOne, numberTwo, numberThree);
}
else if (numberThree < numberTwo && numberTwo < numberOne)
{
Console.WriteLine("Number one : {0} \nNumber two : {1} \nNumber three : {2} ", numberOne, numberTwo, numberThree);
}
}
}