Расположите четыре числа в порядке убывания.(через if) - C#
Формулировка задачи:
Ребят,помогите с задание.Понятия не имею как сделать через If.
Сделал только так:
Но нужно через if!!
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication2
- {
- class Program
- {
- static void Main(string[] args)
- {
- double x, y, x2, y2;
- Console.Write("Введите первое число: ");
- x = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите второе число: ");
- y= Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите третие число: ");
- x2 = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите четвёртое число: ");
- y2 = Convert.ToDouble(Console.ReadLine());
- List<double> dbs = new List<double>();
- dbs.Add(x);
- dbs.Add(y);
- dbs.Add(x2);
- dbs.Add(y2);
- dbs.Sort();
- dbs.Reverse();
- for (int i = 0; i < dbs.Count; i++)
- {
- Console.Write(dbs[i]+" ");
- }
- Console.ReadLine();
- }
- }
- }
Решение задачи: «Расположите четыре числа в порядке убывания.(через if)»
textual
Листинг программы
- List<double> dbs = new List<double>();
- dbs.Add(x);
- dbs.Add(y);
- dbs.Add(x2);
- dbs.Add(y2);
- double temp = 0;
- for (int write = 0; write < dbs.Count; write++)
- {
- for (int sort = 0; sort < dbs.Count - 1; sort++)
- {
- if (dbs[sort] < dbs[sort + 1])
- {
- temp = dbs[sort + 1];
- dbs[sort + 1] = dbs[sort];
- dbs[sort] = temp;
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д