6.7 Ввести три числа A, B, C. Найти сумму двух наибольших из них. Если пользователь введёт числа так, что среди них нельзя будет определить два наибольших - выдать соответствующее сообщение.
using System; namespace ConsoleApp1 { class Program { static void Main() { int a, b, c; Console.WriteLine("Введите 3 целых числа через пробел"); string[] l = Console.ReadLine().Split(' '); if (l.Length < 3) { Console.WriteLine("Вы ввели меньше 3 чисел"); return; } a = Convert.ToInt32(l[0]); b = Convert.ToInt32(l[1]); c = Convert.ToInt32(l[2]); if (a == b && b == c) { Console.WriteLine("Все числа равны"); return; } int s = a + b; if (s <= (a + c)) s = a + c; if (s <= (b + c)) s = b + c; Console.WriteLine("Сумму двух наибольших чисел равна {0}", s); } } } C# using System; namespace ConsoleApp1 { class Program { static void Main() { int a, b, c; Console.WriteLine("Введите 3 целых числа через пробел"); string[] l = Console.ReadLine().Split(' '); if (l.Length < 3) { Console.WriteLine("Вы ввели меньше 3 чисел"); return; } a = Convert.ToInt32(l[0]); b = Convert.ToInt32(l[1]); c = Convert.ToInt32(l[2]); if (a == b && b == c) { Console.WriteLine("Все числа равны"); return; } int s = a + b; if (s <= (a + c)) s = a + c; if (s <= (b + c)) s = b + c; Console.WriteLine("Сумму двух наибольших чисел равна {0}", s); } } } --- Сообщение объединено с предыдущим 13 сен 2022 Немного исправил код, чтобы не вылетали ошибки если будет не число и написал ещё один вариант: using System; namespace ConsoleApp1 { class Program { static void Main() { int a, b, c; Console.WriteLine("Введите 3 целых числа через пробел"); string[] l = Console.ReadLine().Split(' '); if (l.Length < 3) { Console.WriteLine("Вы ввели меньше 3 чисел"); return; } try { a = Convert.ToInt32(l[0]); b = Convert.ToInt32(l[1]); c = Convert.ToInt32(l[2]); } catch { Console.WriteLine("Вы ввели не числи или не целое число"); return; } if (a == b && b == c) { Console.WriteLine("Все числа равны"); return; } int s = a + b; if (s <= (a + c)) s = a + c; if (s <= (b + c)) s = b + c; Console.WriteLine("Сумму двух наибольших чисел равна {0}", s); } } } C# using System; namespace ConsoleApp1 { class Program { static void Main() { int a, b, c; Console.WriteLine("Введите 3 целых числа через пробел"); string[] l = Console.ReadLine().Split(' '); if (l.Length < 3) { Console.WriteLine("Вы ввели меньше 3 чисел"); return; } try { a = Convert.ToInt32(l[0]); b = Convert.ToInt32(l[1]); c = Convert.ToInt32(l[2]); } catch { Console.WriteLine("Вы ввели не числи или не целое число"); return; } if (a == b && b == c) { Console.WriteLine("Все числа равны"); return; } int s = a + b; if (s <= (a + c)) s = a + c; if (s <= (b + c)) s = b + c; Console.WriteLine("Сумму двух наибольших чисел равна {0}", s); } } } === using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main() { List<int> list = new List<int>(); Console.WriteLine("Введите 3 целых числа через пробел"); string[] line = Console.ReadLine().Split(' '); if (line.Length < 3) { Console.WriteLine("Вы ввели меньше 3 чисел"); return; } for (int i = 0; i < line.Length; i++) { if (i > 2) { break; } try { list.Add(Convert.ToInt32(line[i])); } catch { Console.WriteLine("Вы ввели не числи или не целое число"); return; } } if (list[0] == list[1] && list[1] == list[2]) { Console.WriteLine("Все числа равны"); return; } list.Sort(); Console.WriteLine("Сумму двух наибольших чисел равна {0}", list[1] + list[2]); } } } C# using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main() { List<int> list = new List<int>(); Console.WriteLine("Введите 3 целых числа через пробел"); string[] line = Console.ReadLine().Split(' '); if (line.Length < 3) { Console.WriteLine("Вы ввели меньше 3 чисел"); return; } for (int i = 0; i < line.Length; i++) { if (i > 2) { break; } try { list.Add(Convert.ToInt32(line[i])); } catch { Console.WriteLine("Вы ввели не числи или не целое число"); return; } } if (list[0] == list[1] && list[1] == list[2]) { Console.WriteLine("Все числа равны"); return; } list.Sort(); Console.WriteLine("Сумму двух наибольших чисел равна {0}", list[1] + list[2]); } } }