Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class SortDescending3RealValues
- {
- static void Main()
- {
- //Sort 3 real values in descending order using nested if statements.
- Console.Write("Please enter the first real number:");
- decimal firstNum = decimal.Parse(Console.ReadLine());
- Console.Write("Please enter the second real number:");
- decimal secondNum = decimal.Parse(Console.ReadLine());
- Console.Write("Please enter the third real number:");
- decimal thirdNum = decimal.Parse(Console.ReadLine());
- decimal listNum1, listNum2, listNum3;
- if (firstNum >= secondNum)
- if (firstNum >= thirdNum)
- if (secondNum >= thirdNum)
- {
- listNum1 = firstNum;
- listNum2 = secondNum;
- listNum3 = thirdNum;
- }
- else
- {
- listNum1 = firstNum;
- listNum2 = thirdNum;
- listNum3 = secondNum;
- }
- else
- {
- listNum1 = thirdNum;
- listNum2 = firstNum;
- listNum3 = secondNum;
- }
- else
- {
- if (secondNum >= thirdNum)
- {
- listNum1 = secondNum;
- listNum2 = thirdNum;
- listNum3 = firstNum;
- }
- else
- {
- listNum1 = thirdNum;
- listNum2 = secondNum;
- listNum3 = firstNum;
- }
- }
- Console.WriteLine("The entered numbers are:\n {0}\n {1}\n {2}\n", firstNum, secondNum, thirdNum);
- Console.WriteLine("In descending order they look like this:\n {0}\n {1}\n {2}\n", listNum1, listNum2, listNum3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement