Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace lab4
  8. {
  9. public class matrix
  10. {
  11.  
  12. private static Random random = new Random();
  13.  
  14. public static double[,] GenerateMatrix(int rows, int columns, int minRange = 0 , int maxRange = 30)
  15. {
  16. var matrix = new double [rows,columns];
  17.  
  18. for (int i = 0; i < matrix.GetLength(0); i++)
  19. {
  20.  
  21. for (int j = 0; j < matrix.GetLength(1); j++)
  22. {
  23.  
  24. matrix[i, j] = random.Next(minRange, maxRange);
  25.  
  26.  
  27. }
  28.  
  29.  
  30. }
  31.  
  32. return matrix;
  33. }
  34.  
  35. public static void DisplayMatrix(double[,] matrix)
  36. {
  37.  
  38.  
  39. for (int i = 0; i < matrix.GetLength(0); i++)
  40. {
  41.  
  42. for (int j = 0; j < matrix.GetLength(1); j++)
  43. {
  44.  
  45.  
  46. Console.WriteLine("{0}\t", matrix[i, j]);
  47.  
  48.  
  49. }
  50.  
  51.  
  52. }
  53.  
  54.  
  55. }
  56.  
  57. public static int[,] MuliplyMatrices(int[,] tab1, int[,] tab2)
  58. {
  59.  
  60. if (tab1.GetLength(1) != tab2.GetLength(0))
  61. throw new ArgumentException("Liczba macierzy pieerwszej musi byc równa liczbie wierszy drugiek");
  62.  
  63.  
  64. var result = new int[tab1.GetLength(0),tab2.GetLength(1)];
  65.  
  66.  
  67.  
  68. for (int i = 0; i < result.GetLength(0) ; i++)
  69. {
  70.  
  71. for (int j = 0; j < result.GetLength(1); j++)
  72. {
  73.  
  74. int suma = 0;
  75.  
  76. for (int k = 0; k < tab1.GetLength(1); k++)
  77. {
  78.  
  79. suma += tab1[i,k] * tab2[k,j];
  80.  
  81.  
  82. }
  83.  
  84. result[i,j] = suma;
  85.  
  86. }
  87.  
  88. }
  89.  
  90. return result;
  91.  
  92.  
  93.  
  94.  
  95. }
  96.  
  97. public static int MinMax(int[,] table, int row, out int column)
  98. {
  99.  
  100. int[,] vector = new int [table.GetLength(0), 2];
  101.  
  102.  
  103.  
  104. for (int i = 0; i < table.GetLength(0); i++)
  105. {
  106.  
  107. int min = table[i, 0];
  108. int col = 0;
  109. for (int j = 0; j < table.GetLength(1); j++)
  110. {
  111.  
  112. if (table[i, j] < min)
  113. {
  114.  
  115. min = table[i, j];
  116. col = j;
  117.  
  118. }
  119.  
  120. }
  121.  
  122. vector[i, 0] = min;
  123. vector[i, 1] = col;
  124.  
  125. }
  126.  
  127. int max = vector[0, 0];
  128. row = 0;
  129. column = vector[0,1];
  130.  
  131. for (int i = 0; i < vector.GetLength(0); i++)
  132. {
  133.  
  134. if (vector[i,0] > max)
  135. {
  136. max = vector[i, 0];
  137. row = i;
  138. column = vector[0, 1];
  139.  
  140. }
  141.  
  142.  
  143.  
  144. }
  145.  
  146. return max;
  147. }
  148.  
  149.  
  150.  
  151. }
  152.  
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement