mayap

SortThreeNumbers

Apr 11th, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace SortThreeNumbersWithNestedIfs
  8. {
  9.     class SortThreeNumbersWithNestedIfs
  10.     {
  11.         static void Main()
  12.         {
  13.             double a, b, c;
  14.  
  15.             Console.WriteLine("Enter first number: ");
  16.             a = double.Parse(Console.ReadLine());
  17.             Console.WriteLine("Enter second number: ");
  18.             b = double.Parse(Console.ReadLine());
  19.             Console.WriteLine("Enter third number: ");
  20.             c = double.Parse(Console.ReadLine());
  21.  
  22.             Console.WriteLine();
  23.  
  24.             double max = a;
  25.             double middle;
  26.             double min;
  27.  
  28.             if (a > b && a > c)
  29.             {
  30.                 max = a;
  31.                 if (b > c)
  32.                 {
  33.                     middle = b;
  34.                     min = c;
  35.                 }
  36.                 else
  37.                 {
  38.                     middle = c;
  39.                     min = b;
  40.                 }
  41.                 Console.WriteLine("{0,1} {1,1} {2,1}",max,middle,min);
  42.             }
  43.             ///////////////////////
  44.  
  45.             if (b > a && b > c)
  46.             {
  47.                 max = b;
  48.                 if (a > c)
  49.                 {
  50.                     middle = a;
  51.                     min = c;
  52.                 }
  53.                 else
  54.                 {
  55.                     middle = c;
  56.                     min = a;
  57.                 }
  58.                 Console.WriteLine("{0,1} {1,1} {2,1}", max, middle, min);
  59.             }
  60.             /////////////////////////
  61.             if (c > a && c > b)
  62.             {
  63.                 max = c;
  64.                 if (a > b)
  65.                 {
  66.                     middle = a;
  67.                     min = b;
  68.                 }
  69.                 else
  70.                 {
  71.                     middle = b;
  72.                     min = a;
  73.                 }
  74.                 Console.WriteLine("{0,1} {1,1} {2,1}", max, middle, min);
  75.             }
  76.             ////////////////////////
  77.             if (a == b && b == c)
  78.             {
  79.                 Console.WriteLine("{0,1} {1,1} {2,1}", a, b, c);
  80.             }
  81.  
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment