Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 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 ConsoleApplication3
  8. {
  9.     public class Matrix
  10.     {
  11.         private static Random random = new Random();
  12.         public static int[,] GenerateMatrix(int rows, int cols,int minRange = 0, int maxRange = 30)
  13.         {
  14.             var matrix = new int[rows, cols];
  15.             for (int i = 0; i < matrix.GetLength(0); i++)
  16.             {
  17.                 for (int j = 0; j < matrix.GetLength(1); j++)
  18.                 {
  19.                     matrix[i, j] = random.Next(minRange, maxRange);
  20.                 }
  21.             }
  22.             //tutaj kod do generowania macierzy
  23.             return matrix;
  24.         }
  25.         public static void DisplayMatrix(int[,] matrix)
  26.         {
  27.             //getlength 0 lub 1 - zwraca wartość długości kolumn (0) i wierszy (1)
  28.             //getLuoweBound
  29.             //Length - liczba wszytkich wlwmentów tablicy
  30.            
  31.             //tutaj kod od wyswietlania macierzy
  32.             for (int i = 0; i < matrix.GetLength(0); i++)
  33.             {
  34.                 for (int j = 0; j < matrix.GetLength(1); j++)
  35.                 {
  36.                     Console.Write("{0}\t",matrix[i,j]);
  37.                 }
  38.                 Console.WriteLine();
  39.             }
  40.         }
  41.  
  42.         public static int[,] MultiplyMmatrices(int[,] tab1, int[,] tab2)
  43.         {
  44.             if (tab1.GetLength(1) != tab2.GetLength(0))
  45.             {
  46.                 throw new ArgumentException("Liczba kolumn macierzy 1 musi byc równa liczbie wierszy macierzy 2.");  
  47.             }
  48.             var result = new int[tab1.GetLength(1),tab2.GetLength(0)];
  49.             for (int i = 0; i < tab1.GetLength(1); i++)
  50.             {
  51.                 for (int j = 0; j < tab2.GetLength(0); j++)
  52.                 {
  53.                     for (int k = 0; k < tab1.GetLength(1); k++)
  54.                     {
  55.                        
  56.                     }
  57.                 }
  58.             }
  59.             return result;
  60.         }
  61.        
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement