Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.IO;
  4.  
  5. namespace File2
  6. {
  7.     class Program
  8.     {
  9.         const string ERROR_MSG = "wrong";
  10.  
  11.         static int InputIntN(string errorMsg)
  12.         {
  13.             Console.WriteLine("Input N: ");
  14.             string s = Console.ReadLine();
  15.             int N;
  16.             if (!int.TryParse(s, out N) || N<=0)
  17.             {
  18.                 Console.WriteLine(errorMsg);
  19.                 return InputIntN(ERROR_MSG);
  20.             }
  21.  
  22.             return N;
  23.         }
  24.  
  25.  
  26.         static Random rnd = new Random();
  27.  
  28.  
  29.         static double[] ArrayFill(int N)
  30.         {
  31.             double[] arr = new double[N];
  32.  
  33.             for (int i = 0; i < N; i++)
  34.             {
  35.                 double b = rnd.NextDouble() * 200 - 100;
  36.  
  37.                 arr[i] = b;
  38.             }
  39.  
  40.             return arr;
  41.         }
  42.  
  43.         static void Main()
  44.         {
  45.             do
  46.             {
  47.                 int N = InputIntN(ERROR_MSG);
  48.  
  49.                 double[] arr = ArrayFill(N);
  50.  
  51.                 string str = String.Join(" ", arr);
  52.  
  53.                 string file_name = "output.txt";
  54.  
  55.                 using (StreamWriter sw = new StreamWriter(file_name, true, Encoding.Default))
  56.                 {
  57.                     sw.Write(str);
  58.                 }
  59.  
  60.  
  61.                 Console.WriteLine("To exit from program press ESCAPE. To restart this program press any key.....");
  62.             } while (Console.ReadKey(true).Key != ConsoleKey.Escape); //  Повтор решения.
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement