Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- class Programm1
- {
- static void input(int n, int[] a)
- {
- for (int i = 0; i < n; i++)
- {
- while (true)
- {
- if (int.TryParse(Console.ReadLine(), out a[i]))
- {
- if (a[i] < 0)
- {
- a[i] = 0;
- }
- break;
- }
- else
- Console.WriteLine("Введите корректное число");
- }
- }
- }
- static void Main()
- {
- while (true)
- {
- int n;
- Console.WriteLine("Введите количество элементов массива от 1 до 100");
- try
- {
- while (true)
- {
- if (int.TryParse(Console.ReadLine(), out n) && n >= 1 && n <= 100)
- {
- StreamWriter sw = new StreamWriter(@"C:\fds\test");
- double res = 0;
- int[] a = new int[n];
- input(n, a);
- for (int i = 0; i < n; i++)
- {
- res += a[i];
- }
- res = res / a.Length;
- for (int i = 0; i < n; i++)
- {
- sw.Write("{0} ", a[i]);
- }
- sw.WriteLine(Environment.NewLine + "{0:F3}", res);
- sw.Close();
- break;
- }
- else
- Console.WriteLine("Введите количество элементов массива от 1 до 100");
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- Console.WriteLine("Для повтора программы введите yes");
- string rep = Console.ReadLine();
- if (rep == "yes")
- {
- continue;
- }
- else
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement