zed_com

pract10(2)

Nov 11th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. namespace C
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.            
  10.             Random r = new Random();
  11.             StreamWriter f1 = new StreamWriter("C:\\users\\mat1.txt");
  12.             StreamWriter f2 = new StreamWriter("C:\\users\\mat2.txt");
  13.             Console.Write("Количество столбцов:");
  14.             int mj = Convert.ToInt32(Console.ReadLine());
  15.             Console.Write("Количество рядов:");
  16.             int mi = Convert.ToInt32(Console.ReadLine());
  17.             int[,] matx1 = new int[mi,mj];
  18.             int[,] matx2 = new int[mi, mj];
  19.             int[,] matx3 = new int[mi, mj];
  20.             for (int i = 0; i < mi; i++)
  21.                 for (int j = 0; j < mj; j++)
  22.                 {
  23.                     f1.WriteLine(r.Next(1, 100));
  24.                     f2.WriteLine(r.Next(1, 100));
  25.                 }
  26.             f1.Close();
  27.             f2.Close();
  28.             StreamReader mat1 = new StreamReader("C:\\users\\mat1.txt");
  29.             StreamReader mat2 = new StreamReader("C:\\users\\mat2.txt");
  30.             StreamWriter mat3 = new StreamWriter("C:\\users\\mat3.txt");
  31.             for (int i = 0; i < mi; i++)
  32.                 for (int j = 0; j < mj; j++)
  33.                 {
  34.                     matx1[i, j] = Convert.ToInt32(mat1.ReadLine());
  35.                     matx2[i, j] = Convert.ToInt32(mat2.ReadLine());
  36.                 }
  37.             for (int i = 0; i < mi; i++)
  38.                 for (int j = 0; j < mj; j++)
  39.                     for (int g = 0; g < mi; g++)
  40.                     {
  41.                         matx3[i, j] += matx1[i, g] * matx2[g, j];
  42.                     }
  43.             for (int i = 0; i < mi; i++, mat3.WriteLine())
  44.                 for (int j = 0; j < mj; j++)
  45.                     mat3.Write("{0} ", matx3[i, j]);
  46.             mat1.Close();
  47.             mat2.Close();
  48.             mat3.Close();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment