Advertisement
Krissy

Conditional_Statements_T4_SortDescending

Nov 24th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. //Sort 3 real values in descending order using nested if statements.
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. using System.Globalization;
  9.  
  10. namespace _04.SortDescending
  11. {
  12.     class SortDescending
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
  17.             Console.WriteLine("Please enter three numbers:");
  18.             decimal a = decimal.Parse(Console.ReadLine());
  19.             decimal b = decimal.Parse(Console.ReadLine());
  20.             decimal c = decimal.Parse(Console.ReadLine());
  21.  
  22.             if (a>=b)
  23.             {
  24.                 if (a>=c)
  25.                 {
  26.                     if (b>=c)
  27.                     {
  28.                         Console.WriteLine("The numbers in Descending order are: {0} , {1} , {2}.",a,b,c);
  29.                     }
  30.                     else
  31.                     {
  32.                         Console.WriteLine("The numbers in Descending order are: {0} , {1} , {2}.", a, c, b);
  33.                     }
  34.                 }
  35.                 else
  36.                 {
  37.                     Console.WriteLine("The numbers in Descending order are: {0} , {1} , {2}.", c, a, b);
  38.                 }
  39.             }
  40.             else
  41.             {
  42.                 if (b>=c)
  43.                 {
  44.                     if (c>=a)
  45.                     {
  46.                         Console.WriteLine("The numbers in Descending order are: {0} , {1} , {2}.", b, c, a);
  47.                     }
  48.                     else
  49.                     {
  50.                         Console.WriteLine("The numbers in Descending order are: {0} , {1} , {2}.", b, a, c);
  51.                     }
  52.                 }
  53.                 else
  54.                 {
  55.                     Console.WriteLine("The numbers in Descending order are: {0} , {1} , {2}.", c, b, a);
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement