Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static double[,] tab = new double[4, 2];
  12.         static Random r = new Random();
  13.         static string[,] tab1 = new string[4, 2];
  14.         static double[,] tab2 = new double[4, 2];
  15.         static string[] tab3;
  16.         static  int counter = 0;
  17.         static void Main(string[] args)
  18.         {
  19.  
  20.  
  21.  
  22.             System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
  23.             customCulture.NumberFormat.NumberDecimalSeparator = ".";
  24.             System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;
  25.  
  26.  
  27.             wpisywanie();
  28.             zapis();
  29.             FileStream fsOdczyt;
  30.             fsOdczyt = new FileStream("D://KarolPlik1.txt", FileMode.Open);
  31.             StreamReader sr = new StreamReader(fsOdczyt);
  32.             string line1,word1;
  33.    
  34.                     while (( line1 = sr.ReadLine()) != null)
  35.                     {
  36.                      tab3=line1.Split(' ');
  37.                         for (int i = 0; i < 4; i++)
  38.                         {
  39.                             for (int j = 0; j < 2; j++)
  40.                             {
  41.                                 if (tab3[counter] != "")
  42.            tab2[i,j]=(Double.Parse(tab3[counter]));
  43.                                 counter++;
  44.  
  45.                             }
  46.                             counter = 0;
  47.                          
  48.                         }
  49.                        
  50.              
  51.             }
  52.             sr.Close();
  53.            
  54.             //List<double> numbers = new List<double>();
  55.             //foreach (string line in File.ReadAllLines("D://KarolPlik2.txt"))
  56.             //{
  57.             //    foreach (string word in line.Split(' '))
  58.             //    {
  59.             //        if (word != "")
  60.             //            numbers.Add(Double.Parse(word));
  61.  
  62.             //    }
  63.             //}
  64.  
  65.             //for (int i = 0; i < 4; i++)
  66.             //{
  67.             //    for (int j = 0; j < 2; j++)
  68.             //    {
  69.                    
  70.             //        tab2[i, j] = numbers.ElementAt(counter);
  71.             //        counter++;
  72.             //    }
  73.             //}
  74.             Console.ReadKey();
  75.         }
  76.  
  77.         static void zapis()
  78.         {
  79.             FileStream fsZapis;
  80.             fsZapis = new FileStream("D://KarolPlik1.txt", FileMode.OpenOrCreate);
  81.             StreamWriter sw = new StreamWriter(fsZapis);
  82.             for (int i = 0; i < 4; i++)
  83.             {
  84.                 for (int j = 0; j < 2; j++)
  85.                 {
  86.                     sw.Write(tab[i, j] + " ");
  87.  
  88.                 } sw.WriteLine();
  89.             }
  90.             sw.Close();
  91.             Console.WriteLine();
  92.  
  93.             for (int i = 0; i < 4; i++)
  94.             {
  95.                 for (int j = 0; j < 2; j++)
  96.                 {
  97.                     Console.Write(tab1[i, j] + " ");
  98.  
  99.                 }
  100.                 Console.WriteLine();
  101.             }
  102.  
  103.         }
  104.  
  105.         static void wpisywanie()
  106.         {
  107.             for (int i = 0; i < 4; i++)
  108.             {
  109.                 for (int j = 0; j < 2; j++)
  110.                 {
  111.                     tab[i, j] = Math.Round((r.NextDouble() * 15), 2);
  112.  
  113.                 }
  114.             }
  115.             for (int i = 0; i < 4; i++)
  116.             {
  117.                 for (int j = 0; j < 2; j++)
  118.                 {
  119.                     Console.Write(tab[i, j] + "  ");
  120.  
  121.                 }
  122.                 Console.WriteLine();
  123.             }
  124.  
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement