Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. class MatrixMultiply
  2.     {
  3.  
  4.         public int[,] MatrixMultEasy(int[,] left, int[,] right)
  5.         {
  6.             int[,]Matrix = new int[left.GetLength(0), right.GetLength(1)];
  7.  
  8.             for (int i = 0; i < left.GetLength(0); i++)
  9.             {
  10.                 for (int j = 0; j < right.GetLength(1); j++)
  11.                 {
  12.                     int sum = 0;
  13.  
  14.                     for (int k = 0; k < right.GetLength(0); k++)
  15.                     {
  16.                         sum += left[i, k] * left[k, j];
  17.                     }
  18.  
  19.                     Matrix[i, j] = sum;
  20.                 }
  21.  
  22.             }
  23.  
  24.             return (Matrix);
  25.            
  26.         }
  27.  
  28.         public bool CheckOnCorrect(int[,] left, int[,] right)
  29.         {
  30.             if ((left != null) && (right != null))
  31.             {
  32.                 if (left.GetLength(1) != right.GetLength(0))
  33.                 {
  34.                     return (false);
  35.                 }
  36.                 else
  37.                 {
  38.                     return (true);
  39.                 }
  40.             }
  41.             else
  42.             {
  43.                 return (false);
  44.             }
  45.         }
  46.     }
  47.  
  48.     class MatrixSum
  49.     {
  50.         public int[,] Do(int[,] left, int[,] right)
  51.         {
  52.            
  53.             for (int i = 0; i < left.GetLength(0); i++)
  54.             {
  55.                 for (int j = 0; j < right.GetLength(1); j++)
  56.                 {
  57.                     left[i, j] += right[i, j];
  58.                 }
  59.             }
  60.  
  61.             return (left);
  62.         }
  63.  
  64.         public bool CheckOnCorrect(int[,] left, int[,] right)
  65.         {
  66.             if ((left != null)&&(right != null))
  67.             {
  68.  
  69.                 if ((left.GetLength(0) == right.GetLength(0)) && (left.GetLength(1) == right.GetLength(1)))
  70.                 {
  71.                     return (true);
  72.                 }
  73.                 else
  74.                 {
  75.                     return (false);
  76.                 }
  77.             }
  78.             else
  79.             {
  80.                 return (false);
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement