using System; using System.Globalization; class Program { static void Main() {…
- User
using System; using System.Globalization;
class Program { static void Main() { Console.Write("Введите целое число со знаком: "); string input = Console.ReadLine();
if (int.TryParse(input, out int number)) { string result = NumberToWords(number); Console.WriteLine($"Результат: {result}"); } else { Console.WriteLine("Неверный ввод. Пожалуйста, введите целое число."); } } static string NumberToWords(int number) { if (number == 0) { return "ноль"; } else if (number < 0) { return "минус " + NumberToWords(Math.Abs(number)); } string words = ""; if ((number / 1000000) > 0) { words += NumberToWords(number / 1000000) + " миллион "; number %= 1000000; } if ((number / 1000) > 0) { words += NumberToWords(number / 1000) + " тысяча "; number %= 1000; } if ((number / 100) > 0) { words += NumberToWords(number / 100) + " сто "; number %= 100; } if (number > 0) { if (words != "") words += "и "; string[] unitsMap = { "ноль", "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять", "десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать" }; string[] tensMap = { "ноль", "десять", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят", "восемьдесят", "девяносто" }; if (number < 20) { words += unitsMap[number]; } else { words += tensMap[number / 10]; if ((number % 10) > 0) { words += " " + unitsMap[number % 10]; } } } return words; }}
- Assistant
The given program takes an input of an integer, converts it into words, and prints the result.
Starting from the Main method, it prompts the user to input an integer by displaying the message "Введите целое число со знаком: ". It then reads the input from the user using Console.ReadLine() and stores it in the 'input' variable.