Advertisement
Guest User

Untitled

a guest
May 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 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 void Main(string[] args)
  12.         {
  13.             string path = @"C:\file.txt";
  14.             string[] lines = File.ReadAllLines(path);
  15.  
  16.             double[,] mat = new double[lines.Length, lines.Length + 1];
  17.  
  18.             for (int i = 0; i < lines.Length; i++)
  19.             {
  20.                 var strvalues = lines[i].Split('\t');
  21.  
  22.                 for (int j = 0; j < strvalues.Length; j++)
  23.                 {
  24.                     var val = 0.0;
  25.                     var ok = double.TryParse(strvalues[j], out val);
  26.  
  27.                     if (ok)
  28.                     {
  29.                         mat[i, j] = val;
  30.                     }
  31.                     else
  32.                     {
  33.                         Console.WriteLine("Error while reading element [{0},{1}]\n", i, j);
  34.                     }
  35.                 }
  36.             }
  37.  
  38.             for (int i = 0; i < mat.GetLength(0); i++)
  39.             {
  40.                 for (int j = 0; j < mat.GetLength(1); j++)
  41.                 {
  42.                     Console.Write("{0} ", mat[i,j]);
  43.                 }
  44.  
  45.                 Console.WriteLine();
  46.             }
  47.  
  48.             Console.ReadLine();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement