Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <iomanip>
- using namespace std;
- const int x = 5;
- const int y = 6;
- const int m = 10;
- const int n = 20;
- const int k = 30;
- const int a = 10;
- const int b = 10;
- int M3[m][n];
- int M6[x][y];
- int M8[a][b];
- void multiply(int M3[m][n],int M1[m][k],int M2[k][n], unsigned int r, unsigned int c, unsigned int l)
- {
- for (unsigned int r =0; r < m ; r++ )
- {
- for (unsigned int c = 0 ; c<n; c++)
- {
- for(unsigned int l=0; l<k; l++)
- {
- M3[r][c] += M1[r][l]*M2[l][c];
- }
- }
- }
- }
- void printMultiply(int M3[m][n],unsigned int r, unsigned int c)
- {
- for (unsigned int r = 0; r<m; r++)
- {
- for(unsigned int c=0;c<n;c++)
- {
- cout<< setw(2);
- cout << M3[r][c];
- }
- cout << endl;
- }
- }
- void printMatrix(int M1[m][k],unsigned int r,unsigned int c)
- {
- for (unsigned int r = 0; r<m; r++)
- {
- for(unsigned int c=0;c<k;c++)
- {
- cout << setw(2);
- cout << M1[r][c];
- }
- cout << endl;
- }
- }
- void printMatrix2(int M2[k][n], unsigned int r, unsigned int c)
- {
- for (unsigned int r = 0; r<k; r++)
- {
- for(unsigned int c=0;c<n;c++)
- {
- cout<<setw(2);
- cout << M2[r][c];
- }
- cout << endl;
- }
- }
- void printMatrix4(int M4[x][y], unsigned int r, unsigned int c)
- {
- for (unsigned int r = 0; r<x; r++)
- {
- for(unsigned int c=0;c<y;c++)
- {
- cout<<setw(2);
- cout << M4[r][c];
- }
- cout << endl;
- }
- }
- void printMatrix5(int M5[x][y], unsigned int r, unsigned int c)
- {
- for (unsigned int r = 0; r<x; r++)
- {
- for(unsigned int c=0;c<y;c++)
- {
- cout<<setw(2);
- cout << M5[r][c];
- }
- cout << endl;
- }
- }
- void SOUCET(int M6[x][y],int M4[x][y], int M5[x][y], unsigned int r, unsigned int c)
- {
- for (unsigned int r = 0; r<x; r++)
- for(unsigned int c=0; c<y; c++)
- {
- M6[r][c]=M4[r][c]+M5[r][c];
- }
- }
- void printSoucet(int M6[x][y], unsigned int r, unsigned int c)
- {
- for (unsigned int r =0; r<x; r++)
- {
- for (unsigned int c=0; c<y; c++)
- {
- cout<<setw(2);
- cout << M6[r][c];
- }
- cout << endl;
- }
- }
- void printMatrix7(int M7[m][m], unsigned int r, unsigned int c)
- {
- for (unsigned int r = 0; r<m; r++)
- {
- for (unsigned int c = 0; c<m; c++)
- {
- cout<<setw(2);
- cout << M7[r][c];
- }
- cout << endl;
- }
- }
- void TRANSPOSSED(int M8[a][b], int M7[a][b], unsigned int r, unsigned int c)
- {
- for (unsigned int r = 0; r<m; r++)
- {
- for (unsigned int c= 0; c<m; c++)
- {
- M8[r][c]=M7[c][r];
- }
- }
- }
- void printTRANSPOSSED(int M8[a][b], unsigned int r, unsigned int c)
- {
- for (unsigned int r=0; r<a; r++)
- {
- for (unsigned int c=0; c<b; c++)
- {
- cout<<setw(2);
- cout << M8[r][c];
- }
- cout << endl;
- }
- }
- void upperTriang(int M7[a][b], unsigned r, unsigned c)
- {
- for (unsigned int r=0; r < a; r++)
- {
- for (unsigned int c=0; c< b ; c++)
- {
- if (c>r)
- {
- cout<<setw(2)<< M7[r][c];
- }
- else
- {
- cout <<setw(2) << ' ';
- }
- }
- cout << endl;
- }
- }
- void lowerTriang(int M7[a][b], unsigned r, unsigned c)
- {
- for (unsigned int r=0; r < a; r++)
- {
- for (unsigned int c=0; c< b ; c++)
- {
- if (c<r)
- {
- cout<<setw(2)<< M7[r][c];
- }
- else
- {
- cout <<setw(2) << ' ';
- }
- }
- cout << endl;
- }
- }
- void rotateBYdiagonal(int M7[a][b], unsigned int r, unsigned int c)
- {
- for (unsigned int r=0; r<a; r++)
- {
- for (unsigned int c=0; c<b; c++)
- {
- if (c != r)
- {
- cout << setw(2) << M7[c][r];
- }
- else
- {
- cout<< setw(2) << M7[r][c];
- }
- }
- cout << endl;
- }
- }
- void diagonal(int M7[a][b], unsigned r, unsigned c)
- {
- for (unsigned int r=0; r < a; r++)
- {
- for (unsigned int c=0; c< b ; c++)
- {
- if (c==r)
- {
- cout<<setw(2)<< M7[r][c];
- }
- else
- {
- cout<<setw(2)<< ' ';
- }
- }
- cout << endl;
- }
- }
- int main()
- {
- int M1[m][k];
- int M2[k][n];
- int M4[x][y];
- int M5[x][y];
- int M7[m][m];
- for (unsigned int i=0; i < m ; i++)
- for (unsigned int j=0; j < k; j++)
- {
- M1[i][j]=2;
- }
- for (unsigned int i=0; i < k ; i++)
- for (unsigned int j=0; j < n; j++)
- {
- M2[i][j]=1;
- }
- for (unsigned int i=0; i < x ; i++)
- for (unsigned int j=0; j < y; j++)
- {
- M4[i][j]=6;
- }
- for (unsigned int i=0; i < x ; i++)
- for (unsigned int j=0; j < y; j++)
- {
- M5[i][j]=5;
- }
- for (unsigned int i=0; i < m ; i++)
- for (unsigned int j=0; j < m; j++)
- {
- M7[i][j] = rand()%10;
- }
- multiply(M3,M1,M2,m,n,k);
- printMatrix(M1,m,k);
- printMatrix2(M2,k,n);
- printMultiply(M3,m,n);
- printMatrix4(M4,x,y);
- printMatrix5(M5,x,y);
- SOUCET(M6,M4,M5,x,y);
- printSoucet(M6,x,y);
- printMatrix7(M7,a,b);
- cout << endl;
- TRANSPOSSED(M8,M7,a,b);
- printTRANSPOSSED(M8,a,b);
- cout << endl;
- upperTriang(M7,a,b);
- cout << endl;
- lowerTriang(M7,a,b);
- cout << endl;
- diagonal(M7,a,b);
- cout << endl;
- rotateBYdiagonal(M7,a,b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment