Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace lab4
- {
- public class matrix
- {
- private static Random random = new Random();
- public static double[,] GenerateMatrix(int rows, int columns, int minRange = 0 , int maxRange = 30)
- {
- var matrix = new double [rows,columns];
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- matrix[i, j] = random.Next(minRange, maxRange);
- }
- }
- return matrix;
- }
- public static void DisplayMatrix(double[,] matrix)
- {
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- Console.WriteLine("{0}\t", matrix[i, j]);
- }
- }
- }
- public static int[,] MuliplyMatrices(int[,] tab1, int[,] tab2)
- {
- if (tab1.GetLength(1) != tab2.GetLength(0))
- throw new ArgumentException("Liczba macierzy pieerwszej musi byc równa liczbie wierszy drugiek");
- var result = new int[tab1.GetLength(0),tab2.GetLength(1)];
- for (int i = 0; i < result.GetLength(0) ; i++)
- {
- for (int j = 0; j < result.GetLength(1); j++)
- {
- int suma = 0;
- for (int k = 0; k < tab1.GetLength(1); k++)
- {
- suma += tab1[i,k] * tab2[k,j];
- }
- result[i,j] = suma;
- }
- }
- return result;
- }
- public static int MinMax(int[,] table, int row, out int column)
- {
- int[,] vector = new int [table.GetLength(0), 2];
- for (int i = 0; i < table.GetLength(0); i++)
- {
- int min = table[i, 0];
- int col = 0;
- for (int j = 0; j < table.GetLength(1); j++)
- {
- if (table[i, j] < min)
- {
- min = table[i, j];
- col = j;
- }
- }
- vector[i, 0] = min;
- vector[i, 1] = col;
- }
- int max = vector[0, 0];
- row = 0;
- column = vector[0,1];
- for (int i = 0; i < vector.GetLength(0); i++)
- {
- if (vector[i,0] > max)
- {
- max = vector[i, 0];
- row = i;
- column = vector[0, 1];
- }
- }
- return max;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement