Advertisement
nedoproger

лаба2з2

Nov 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Лаба2задание2
  4. {
  5. class Program
  6. {
  7. private static void Main(string[] args)
  8. {
  9. int max = Int32.MinValue; // текущее максимальное число
  10. int min = Int32.MaxValue; // текущее минимальное число
  11. bool ok = true;
  12. do
  13. {
  14. if (!ok)
  15. {
  16. Console.WriteLine("Ошибка! Введите другое число");
  17. max = Int32.MinValue;
  18. min = Int32.MaxValue;
  19. }
  20.  
  21. Console.WriteLine("Введите число:");
  22. int a;
  23. ok = Int32.TryParse(Console.ReadLine(), out a);
  24. if (ok)
  25. {
  26.  
  27. if (a != 0)
  28. {
  29.  
  30. if (max < a)
  31. max = a;
  32.  
  33. if (min > a)
  34. min = a;
  35. }
  36. else
  37. break;
  38. }
  39.  
  40. }
  41. while (true);
  42.  
  43. Console.WriteLine(" Сумма максимального значения {0} и минимального значения {1}: {2}", max, min, max + min);
  44.  
  45. Console.WriteLine("Нажмите клавишу enter для завершения работы");
  46. Console.ReadKey();
  47.  
  48.  
  49. }
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement