Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //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:
- class Sort3NumbersWithNestedIfs
- {
- static void Main()
- {
- Console.Write("Enter the first number: ");
- double a = double.Parse(Console.ReadLine());
- Console.Write("Enter the second number: ");
- double b = double.Parse(Console.ReadLine());
- Console.Write("Enter the third number: ");
- double c = double.Parse(Console.ReadLine());
- if ((a>c) && (a>b))
- {
- if (b > c)
- {
- Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", a, b, c);
- }
- else
- {
- Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", a, c, b);
- }
- }
- if ((b>a) && (b>c))
- {
- if (a>c)
- {
- Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", b, a, c);
- }
- else
- {
- Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", b, c, a);
- }
- }
- if ((c>a)&& (c>b))
- {
- if (a>b)
- {
- Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", c, a, b);
- }
- else
- {
- Console.WriteLine("The numbers in descending order: {0}, {1}, {2}", c, b, a);
- }
- }
- else if ((a == b) &&(b == c))
- {
- Console.WriteLine("The nimbers are equal: {0},{1},{2}", a, b, c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement