mmayoub

Ex01, 21.06.2021

Jun 25th, 2021 (edited)
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Ex21062021
  4. {
  5.     class Program
  6.     {
  7.         static void Main1(string[] args)
  8.         {
  9.             int a, b, c;    // Three numbers for input
  10.             int avg;        // average of the input numbers
  11.            
  12.             // get first number
  13.             Console.Write("Enter a number: ");
  14.             a = int.Parse(Console.ReadLine());
  15.  
  16.             // get second number
  17.             Console.Write("Enter second number: ");
  18.             b = int.Parse(Console.ReadLine());
  19.  
  20.             // get third number
  21.             Console.Write("Enter Third number: ");
  22.             c = int.Parse(Console.ReadLine());
  23.  
  24.             // calculate the average
  25.             avg = (a + b + c) / 3;
  26.             // print results:  average
  27.             Console.WriteLine("average is " + avg);
  28.  
  29.             // print numbers in ascending order
  30.             // 6 options: abc, acb, bac, bca, cab, aba
  31.  
  32.             // option 1 : a (min), then b (mid) then c (max)
  33.             if ((a <= b) && (b <= c))
  34.                 Console.WriteLine("The numbers are: {0} , {1} , {2}",a,b,c);
  35.             else
  36.             // option 2 : a (min), then c (mid) then b (max)
  37.             if ((a <= c) && (c <= b))
  38.                 Console.WriteLine("The numbers are: {0} , {1} , {2}", a, c, b);
  39.             else
  40.             // option 3 : b (min), then a (mid) then c (max)
  41.             if ((b <= a) && (a <= c))
  42.                 Console.WriteLine("The numbers are: {0} , {1} , {2}", b, a, c);
  43.             else
  44.             // option 4 : b (min), then c (mid) then a (max)
  45.             if ((b <= c) && (c <= a))
  46.                 Console.WriteLine("The numbers are: {0} , {1} , {2}", b, c, a);
  47.             else
  48.             // option 5 : c (min), then a (mid) then b (max)
  49.             if ((c <= a) && (a <= b))
  50.                 Console.WriteLine("The numbers are: {0} , {1} , {2}", c, a, b);
  51.             else
  52.             // option 6 : c (min), then b (mid) then a (max)
  53.             if ((c <= b) && (b <= a))
  54.                 Console.WriteLine("The numbers are: {0} , {1} , {2}", c, b, a);
  55.         }
  56.     }
  57. }
  58.  
Add Comment
Please, Sign In to add comment