Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace ConsoleApplication1
- {
- class Program
- {
- static double[,] tab = new double[4, 2];
- static Random r = new Random();
- static string[,] tab1 = new string[4, 2];
- static double[,] tab2 = new double[4, 2];
- static string[] tab3;
- static int counter = 0;
- static void Main(string[] args)
- {
- System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
- customCulture.NumberFormat.NumberDecimalSeparator = ".";
- System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
- wpisywanie();
- zapis();
- FileStream fsOdczyt;
- fsOdczyt = new FileStream("D://KarolPlik1.txt", FileMode.Open);
- StreamReader sr = new StreamReader(fsOdczyt);
- string line1,word1;
- while (( line1 = sr.ReadLine()) != null)
- {
- tab3=line1.Split(' ');
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- if (tab3[counter] != "")
- tab2[i,j]=(Double.Parse(tab3[counter]));
- counter++;
- }
- counter = 0;
- }
- }
- sr.Close();
- //List<double> numbers = new List<double>();
- //foreach (string line in File.ReadAllLines("D://KarolPlik2.txt"))
- //{
- // foreach (string word in line.Split(' '))
- // {
- // if (word != "")
- // numbers.Add(Double.Parse(word));
- // }
- //}
- //for (int i = 0; i < 4; i++)
- //{
- // for (int j = 0; j < 2; j++)
- // {
- // tab2[i, j] = numbers.ElementAt(counter);
- // counter++;
- // }
- //}
- Console.ReadKey();
- }
- static void zapis()
- {
- FileStream fsZapis;
- fsZapis = new FileStream("D://KarolPlik1.txt", FileMode.OpenOrCreate);
- StreamWriter sw = new StreamWriter(fsZapis);
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- sw.Write(tab[i, j] + " ");
- } sw.WriteLine();
- }
- sw.Close();
- Console.WriteLine();
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- Console.Write(tab1[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- static void wpisywanie()
- {
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- tab[i, j] = Math.Round((r.NextDouble() * 15), 2);
- }
- }
- for (int i = 0; i < 4; i++)
- {
- for (int j = 0; j < 2; j++)
- {
- Console.Write(tab[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement