using System;
using
System.IO;
using static System.Console;
namespace HelloApp
{
class Program
{
static void Main(string[] args)
{
string path = "Lab_8_1.txt";
WriteLine("Введiть числа (через пропуск):");
string text = ReadLine();
string[] sArray = text.Split();
double[] dArray = new double[text.Length];
double largest_negat_elem = 0; // Найбільший вiд'ємний елемент.
try
{
// Запис файлу:
using (StreamWriter sw = new StreamWriter(path, false, System.Text.Encoding.UTF8))
{
sw.WriteLine(text);
// Пошук найбільшого від'ємного елементу у файлі:
for (int i = 0; i < sArray.Length; i++)
{
dArray[i] = Convert.ToDouble(sArray[i]);
if (largest_negat_elem > dArray[i])
largest_negat_elem = dArray[i];
}
}
// Читання файлу:
using (StreamReader sr = new StreamReader(path))
{
WriteLine("\nВмiст файлу:");
WriteLine(sr.ReadToEnd());
WriteLine($"Найбiльший вiд'ємний елемент: {largest_negat_elem}");
}
ReadKey();
}
catch (Exception e)
{
WriteLine(e.Message);
}
}
}
}