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 ConsoleApplication4
- {
- class Program
- {
- public static void modulus(int[,] matrix, int n,int m)
- {
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- if (matrix[i, j] % 2 == 0) matrix[i, j] = 0;
- else matrix[i, j] = 1;
- }
- }
- }
- public static void beir(int[,] matrix,int n,int m) //mátrix elemeinek megadása
- {
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < m; j++)
- {
- Console.Write("Adja meg a matrix {0},{1}. elemet: ", i + 1, j + 1);matrix[i, j] = Convert.ToInt32(Console.ReadLine());
- }
- Console.WriteLine();
- }
- }
- public static void beir_rnd(int[,] matrix, int n, int m) //pszeudo randomszám generátor
- {
- Random rnd = new Random();
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- matrix[i, j] = rnd.Next(0, 100);
- }
- Console.WriteLine();
- }
- }
- public static void kiir(int[,] matrix, int n, int m) //mátrix kiíratása
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- Console.Write("{0} \t",matrix[i,j]);
- }
- Console.WriteLine("\n");
- }
- }
- public static void szorzas(int[,] matrix,int[,] matrix1,int n,int m)
- {
- int[,] matrix2 = new int[100, 100];
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- for (int k=0;k<m;k++)
- {
- matrix2[i, j] += matrix[i, k] * matrix[k, j];
- }
- }
- }
- //modulus(matrix2, n, m);
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- Console.Write("{0} \t",matrix2[i, j]);
- }
- Console.WriteLine("\n");
- }
- }
- static void Main(string[] args)
- {
- int[,] matrix = new int[100, 100];
- int[,] matrix1 = new int[100, 100];
- int sorszam, oszlopszam, sorszam1, oszlopszam1;
- byte uj = 1;
- do
- {
- do //sor és oszlopszám megadása amig nem NxK, KxM alakban vannak
- {
- Console.WriteLine("Adja meg az elso matrix sorszamat: ");
- sorszam = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Adja meg az elso matrix oszlopszamat: ");
- oszlopszam = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Adja meg a masodik matrix sorszamat: ");
- sorszam1 = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Adja meg a masodik matrix oszlopszamat: ");
- oszlopszam1 = Convert.ToInt32(Console.ReadLine());
- if (oszlopszam != sorszam1) Console.WriteLine("Ilyen alaku matrixokat nem lehet szorozni!");
- } while (oszlopszam != sorszam1);
- Console.WriteLine("elemek megadásának módja: ");
- Console.WriteLine("1 - kézi/2 - randomszám generátor");
- byte mod = Convert.ToByte(Console.ReadLine());
- switch (mod)
- {
- case 1:
- beir(matrix, sorszam, oszlopszam);
- beir(matrix1, sorszam1, oszlopszam1);
- break;
- case 2:
- beir_rnd(matrix, sorszam, oszlopszam);
- beir_rnd(matrix1, sorszam1, oszlopszam1);
- break;
- }
- Console.WriteLine("Elso matrix: ");
- kiir(matrix, sorszam, oszlopszam);
- Console.WriteLine("Masodik matrix: ");
- kiir(matrix1, sorszam1, oszlopszam1);
- Console.WriteLine("Ket matrix szorzata: ");
- szorzas(matrix, matrix1, sorszam, oszlopszam1);
- Console.WriteLine("Uj matrix: 1/Kilepes: 0");
- uj = Convert.ToByte(Console.ReadLine());
- } while (uj == 1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement