Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Ex21062021
- {
- class Program
- {
- static void Main1(string[] args)
- {
- int a, b, c; // Three numbers for input
- int avg; // average of the input numbers
- // get first number
- Console.Write("Enter a number: ");
- a = int.Parse(Console.ReadLine());
- // get second number
- Console.Write("Enter second number: ");
- b = int.Parse(Console.ReadLine());
- // get third number
- Console.Write("Enter Third number: ");
- c = int.Parse(Console.ReadLine());
- // calculate the average
- avg = (a + b + c) / 3;
- // print results: average
- Console.WriteLine("average is " + avg);
- // print numbers in ascending order
- // 6 options: abc, acb, bac, bca, cab, aba
- // option 1 : a (min), then b (mid) then c (max)
- if ((a <= b) && (b <= c))
- Console.WriteLine("The numbers are: {0} , {1} , {2}",a,b,c);
- else
- // option 2 : a (min), then c (mid) then b (max)
- if ((a <= c) && (c <= b))
- Console.WriteLine("The numbers are: {0} , {1} , {2}", a, c, b);
- else
- // option 3 : b (min), then a (mid) then c (max)
- if ((b <= a) && (a <= c))
- Console.WriteLine("The numbers are: {0} , {1} , {2}", b, a, c);
- else
- // option 4 : b (min), then c (mid) then a (max)
- if ((b <= c) && (c <= a))
- Console.WriteLine("The numbers are: {0} , {1} , {2}", b, c, a);
- else
- // option 5 : c (min), then a (mid) then b (max)
- if ((c <= a) && (a <= b))
- Console.WriteLine("The numbers are: {0} , {1} , {2}", c, a, b);
- else
- // option 6 : c (min), then b (mid) then a (max)
- if ((c <= b) && (b <= a))
- Console.WriteLine("The numbers are: {0} , {1} , {2}", c, b, a);
- }
- }
- }
Add Comment
Please, Sign In to add comment