Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem 7. Sort 3 Numbers with Nested Ifs
- //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.
- using System;
- class Sort3Numbers
- {
- static void Main()
- {
- Console.Write("Please, enter a:");
- double a = double.Parse(Console.ReadLine());
- Console.Write("Please, enter b:");
- double b = double.Parse(Console.ReadLine());
- Console.Write("Please, enter c:");
- double c = double.Parse(Console.ReadLine());
- //Sorting in descending order
- if (a > b && a > c)
- {
- if (b > c)
- {
- Console.WriteLine("Result:" + a + " " + b + " " + c);
- }
- else
- {
- Console.WriteLine("Result:" + a + " " + c + " " + b);
- }
- }
- else if (b > a && b > c)
- {
- if (a > c)
- {
- Console.WriteLine("Result:" + b + " " + a + " " + c);
- }
- else
- {
- Console.WriteLine("Result:" + b + " " + c + " " + a);
- }
- }
- else if (c > a && c > b)
- {
- if (a > b)
- {
- Console.WriteLine("Result:" + c + " " + a + " " + b);
- }
- else
- {
- Console.WriteLine("Result:"+ c + " " + b + " " + a);
- }
- }
- else
- Console.WriteLine("Result:" + a + " " + b + " " + c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement