Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.90 KB | None | 0 0
  1. using System;
  2. using System.Windows.Forms;
  3. using System.IO;
  4. namespace Сложение_матриц
  5. {
  6.     public partial class Form1 : Form
  7.     {
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.         }
  12.         private void button1_Click(object sender, EventArgs e)
  13.  
  14.         {
  15.             {
  16.  
  17.                 {
  18.                     StreamReader fileReader = new StreamReader("d:/1111.txt");
  19.                     string isxodFile = fileReader.ReadToEnd();
  20.                     fileReader.Close();
  21.                     string[] fileMatrix = isxodFile.Split(new[] { "\r\n\r\n" }, StringSplitOptions.None);
  22.                     string[] ur_1 = fileMatrix[0].Split('\n');
  23.                     string[] ur_2 = fileMatrix[1].Split('\n');
  24.                     string[] line = ur_1[0].Split(' ');
  25.                     int[,] matrix_1 = new int[ur_1.Length, line.Length];
  26.                     int[,] matrix_2 = new int[ur_2.Length, line.Length];
  27.  
  28.                     for (int i = 0; i < ur_1.Length; i++)
  29.                     {
  30.                         line = ur_1[i].Split(' ');
  31.                         for (int j = 0; j < line.Length; j++)
  32.                             matrix_1[i, j] = Convert.ToInt16(line[j]);
  33.                         line = ur_2[i].Split(' ');
  34.                         for (int j = 0; j < line.Length; j++)
  35.                         {
  36.                             matrix_2[i, j] = Convert.ToInt16(line[j]);
  37.                             richTextBox1.Text += Convert.ToString(matrix_1[i, j] + matrix_2[i, j]) + '\t';
  38.                         }
  39.                         richTextBox1.Text += '\n';
  40.                     }
  41.                 }
  42.             }
  43.         }
  44.    
  45.  
  46.  
  47.         private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
  48.         {
  49.             openFileDialog1.Filter = " Текстовый фйл| *.txt";
  50.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  51.                 richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
  52.         }
  53.  
  54.         private void СохранитьToolStripMenuItem_Click(object sender, EventArgs e)
  55.         {
  56.             saveFileDialog1.Filter = " Текстовый фйл| *.txt";
  57.             if (saveFileDialog1.ShowDialog() == DialogResult.OK)
  58.                 richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
  59.         }
  60.  
  61.         private void выходToolStripMenuItem1_Click(object sender, EventArgs e)
  62.         {
  63.             this.Close();
  64.         }
  65.  
  66.         private void Form1_Load(object sender, EventArgs e)
  67.         {
  68.  
  69.         }
  70.  
  71.         private void справкаToolStripMenuItem1_Click(object sender, EventArgs e)
  72.         {
  73.             MessageBox.Show("Выберете файл с 2 матрицами,разделенными пустой строкой,затем нажмите сумма или разность.");
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement