Advertisement
VyaraG

Sort3NumbersWithNestedIfs

Nov 29th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2.  
  3. //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. Examples:
  4.  
  5. class Sort3NumbersWithNestedIfs
  6. {
  7.     static void Main()
  8.     {
  9.         Console.Write("Enter the first number: ");
  10.         double a = double.Parse(Console.ReadLine());
  11.         Console.Write("Enter the second number: ");
  12.         double b = double.Parse(Console.ReadLine());
  13.         Console.Write("Enter the third number: ");
  14.         double c = double.Parse(Console.ReadLine());
  15.  
  16.         if ((a>c) && (a>b))
  17.         {
  18.             if (b > c)
  19.             {
  20.                 Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", a, b, c);
  21.             }
  22.             else
  23.             {
  24.                 Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", a, c, b);
  25.             }
  26.         }
  27.         if ((b>a) && (b>c))
  28.         {
  29.             if (a>c)
  30.             {
  31.                 Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", b, a, c);
  32.             }
  33.             else
  34.             {
  35.                 Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", b, c, a);
  36.             }
  37.            
  38.         }
  39.         if ((c>a)&& (c>b))
  40.         {
  41.             if (a>b)
  42.             {
  43.                 Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", c, a, b);
  44.             }
  45.             else
  46.             {
  47.                 Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", c, b, a);
  48.             }
  49.         }
  50.         else if ((a == b) &&(b == c))
  51.         {
  52.             Console.WriteLine("The nimbers are equal: {0},{1},{2}", a, b, c);
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement