Advertisement
AnitaN

05.ConditionalStatementsHomework/07.Sort3Numbers

Mar 29th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. //Problem 7. Sort 3 Numbers with Nested Ifs
  2. //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.
  3.  
  4. using System;
  5.  
  6. class Sort3Numbers
  7. {
  8.     static void Main()
  9.     {
  10.         Console.Write("Please, enter a:");
  11.         double a = double.Parse(Console.ReadLine());
  12.         Console.Write("Please, enter b:");
  13.         double b = double.Parse(Console.ReadLine());
  14.         Console.Write("Please, enter c:");
  15.         double c = double.Parse(Console.ReadLine());
  16.         //Sorting in descending order
  17.         if (a > b && a > c)
  18.         {
  19.             if (b > c)
  20.             {
  21.                 Console.WriteLine("Result:" + a + " " + b + " " + c);
  22.             }
  23.             else
  24.             {
  25.                 Console.WriteLine("Result:" + a + " " + c + " " + b);
  26.             }
  27.         }
  28.         else if (b > a && b > c)
  29.         {
  30.             if (a > c)
  31.             {
  32.                 Console.WriteLine("Result:" + b + " " + a + " " + c);
  33.             }
  34.             else
  35.             {
  36.                 Console.WriteLine("Result:" + b + " " + c + " " + a);
  37.             }
  38.         }
  39.         else if (c > a && c > b)
  40.         {
  41.             if (a > b)
  42.             {
  43.                 Console.WriteLine("Result:" + c + " " + a + " " + b);
  44.             }
  45.             else
  46.             {
  47.                 Console.WriteLine("Result:"+ c + " " + b + " " + a);
  48.             }
  49.         }
  50.         else
  51.             Console.WriteLine("Result:" + a + " " + b + " " + c);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement