Даны четыре числа. Вывести наименьшее и наибольшее из них - C#
Формулировка задачи:
Здравствуйте, помогите пожалуйста исправить код, вот задача:
Даны четыре числа. Вывести наименьшее и наибольшее из них.
Заранее благодарю
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Situation4
{
class Program
{
static void Main(string[] args)
{
int a, b, c, d, min, max;
Console.Write("Введите число a: ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Введите число b: ");
b = Convert.ToInt32(Console.ReadLine());
Console.Write("Введите число c: ");
c = Convert.ToInt32(Console.ReadLine());
Console.Write("Введите число d: ");
d = Convert.ToInt32(Console.ReadLine());
if ((a > b) && (a > c) && (a > d)) max = a;
if ((b > a) && (b > c) && (b > d)) max = b;
if ((c > a) && (c > b) && (c > d)) max = c;
if ((d > a) && (d > b) && (d > c)) max = d;
if ((a < b) && (a < c) && (a < d)) min = a;
if ((b < a) && (b < c) && (b < d)) min = b;
if ((c < a) && (c < b) && (c < d)) min = c;
if ((d < a) && (d < b) && (d < c)) min = d;
Console.WriteLine("\nНаименьшее число " + min);
Console.WriteLine("Наибольшее число " + max);
}
Console.ReadKey();
}
}
}Решение задачи: «Даны четыре числа. Вывести наименьшее и наибольшее из них»
textual
Листинг программы
var min = new[] { a, b, c, d }.Min();
var max = new[] { a, b, c, d }.Max();