Advertisement
Guest User

SR3

a guest
Oct 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. class Programm1
  4. {
  5. static void input(int n, int[] a)
  6. {
  7. for (int i = 0; i < n; i++)
  8. {
  9. while (true)
  10. {
  11. if (int.TryParse(Console.ReadLine(), out a[i]))
  12. {
  13. if (a[i] < 0)
  14. {
  15. a[i] = 0;
  16. }
  17. break;
  18. }
  19. else
  20. Console.WriteLine("Введите корректное число");
  21. }
  22. }
  23. }
  24. static void Main()
  25. {
  26. while (true)
  27. {
  28. int n;
  29. Console.WriteLine("Введите количество элементов массива от 1 до 100");
  30. try
  31. {
  32. while (true)
  33. {
  34. if (int.TryParse(Console.ReadLine(), out n) && n >= 1 && n <= 100)
  35. {
  36. StreamWriter sw = new StreamWriter(@"C:\fds\test");
  37. double res = 0;
  38. int[] a = new int[n];
  39. input(n, a);
  40. for (int i = 0; i < n; i++)
  41. {
  42. res += a[i];
  43. }
  44. res = res / a.Length;
  45. for (int i = 0; i < n; i++)
  46. {
  47. sw.Write("{0} ", a[i]);
  48. }
  49. sw.WriteLine(Environment.NewLine + "{0:F3}", res);
  50. sw.Close();
  51. break;
  52. }
  53. else
  54. Console.WriteLine("Введите количество элементов массива от 1 до 100");
  55. }
  56.  
  57. }
  58. catch (Exception e)
  59. {
  60. Console.WriteLine(e.Message);
  61. }
  62. Console.WriteLine("Для повтора программы введите yes");
  63. string rep = Console.ReadLine();
  64. if (rep == "yes")
  65. {
  66. continue;
  67. }
  68. else
  69. break;
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement