Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.IO;
- namespace File2
- {
- class Program
- {
- const string ERROR_MSG = "wrong";
- static int InputIntN(string errorMsg)
- {
- Console.WriteLine("Input N: ");
- string s = Console.ReadLine();
- int N;
- if (!int.TryParse(s, out N) || N<=0)
- {
- Console.WriteLine(errorMsg);
- return InputIntN(ERROR_MSG);
- }
- return N;
- }
- static Random rnd = new Random();
- static double[] ArrayFill(int N)
- {
- double[] arr = new double[N];
- for (int i = 0; i < N; i++)
- {
- double b = rnd.NextDouble() * 200 - 100;
- arr[i] = b;
- }
- return arr;
- }
- static void Main()
- {
- do
- {
- int N = InputIntN(ERROR_MSG);
- double[] arr = ArrayFill(N);
- string str = String.Join(" ", arr);
- string file_name = "output.txt";
- using (StreamWriter sw = new StreamWriter(file_name, true, Encoding.Default))
- {
- sw.Write(str);
- }
- Console.WriteLine("To exit from program press ESCAPE. To restart this program press any key.....");
- } while (Console.ReadKey(true).Key != ConsoleKey.Escape); // Повтор решения.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement