Advertisement
sylviapsh

Sort Descending 3 Real Values

Dec 28th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. class SortDescending3RealValues
  3. {
  4.   static void Main()
  5.   {
  6.     //Sort 3 real values in descending order using nested if statements.
  7.  
  8.     Console.Write("Please enter the first real number:");
  9.     decimal firstNum = decimal.Parse(Console.ReadLine());
  10.     Console.Write("Please enter the second real number:");
  11.     decimal secondNum = decimal.Parse(Console.ReadLine());
  12.     Console.Write("Please enter the third real number:");
  13.     decimal thirdNum = decimal.Parse(Console.ReadLine());
  14.     decimal listNum1, listNum2, listNum3;
  15.  
  16.     if (firstNum >= secondNum)
  17.       if (firstNum >= thirdNum)
  18.         if (secondNum >= thirdNum)
  19.         {
  20.           listNum1 = firstNum;
  21.           listNum2 = secondNum;
  22.           listNum3 = thirdNum;
  23.         }
  24.         else
  25.       {
  26.         listNum1 = firstNum;
  27.         listNum2 = thirdNum;
  28.         listNum3 = secondNum;
  29.       }
  30.       else
  31.       {
  32.         listNum1 = thirdNum;
  33.         listNum2 = firstNum;
  34.         listNum3 = secondNum;
  35.       }
  36.     else
  37.     {
  38.       if (secondNum >= thirdNum)
  39.       {
  40.         listNum1 = secondNum;
  41.         listNum2 = thirdNum;
  42.         listNum3 = firstNum;
  43.       }
  44.       else
  45.       {
  46.         listNum1 = thirdNum;
  47.         listNum2 = secondNum;
  48.         listNum3 = firstNum;
  49.       }
  50.     }
  51.     Console.WriteLine("The entered numbers are:\n {0}\n {1}\n {2}\n", firstNum, secondNum, thirdNum);
  52.     Console.WriteLine("In descending order they look like this:\n {0}\n {1}\n {2}\n", listNum1, listNum2, listNum3);
  53.   }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement