fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n;
  7. cin>>n;
  8. int**x=new int* [n];
  9. for(int i=0;i<n;i++){
  10. x[i]=new int[n];
  11. }
  12. int**y=new int* [n];
  13. for(int i=0;i<n;i++){
  14. y[i]=new int[n];
  15. }
  16. int**z=new int* [n];
  17. for(int i=0;i<n;i++){
  18. z[i]=new int[n];
  19. }
  20.  
  21.  
  22. srand (time(NULL));
  23. for(int i=0;i<n;i++ ){
  24. for(int j=0;j<n;j++){
  25. x[i][j]=(rand() % 11);
  26. }
  27.  
  28. }
  29. for(int i=0;i<n;i++ ){
  30. for(int j=0;j<n;j++){
  31. // y[i][j]=(rand() % 11)*4-20;
  32. if (i==j) y[i][j]=1;
  33. else y[i][j]=0;
  34. }
  35.  
  36.  
  37. }
  38. for(int i=0;i<n;i++){
  39. for(int j=0;j<n;j++){
  40. int s=0;
  41. for(int p=0;p<n;p++){
  42. s=s+x[i][p]*y[p][j];
  43. }
  44. z[i][j]=s;
  45. }
  46. }
  47.  
  48.  
  49.  
  50. cout<<"X="<<endl;
  51. for(int i=0;i<n;i++ ){
  52. for(int j=0;j<n;j++){
  53. cout<<x[i][j]<<" ";
  54. }
  55. cout<<endl;
  56.  
  57. }
  58. cout<<"Y="<<endl;
  59. for(int i=0;i<n;i++ ){
  60. for(int j=0;j<n;j++){
  61. cout<<y[i][j]<<" ";
  62. }
  63. cout<<endl;
  64.  
  65. }
  66. cout<<"Z="<<endl;
  67.  
  68. for(int i=0;i<n;i++ ){
  69. for(int j=0;j<n;j++){
  70. if (i>=j) cout<<0<<" ";
  71. else cout<<z[i][j]<<" ";
  72. }
  73. cout<<endl;
  74. }
  75.  
  76. cout<<"Z="<<endl;
  77.  
  78. for(int i=0;i<n;i++ ){
  79. for(int j=0;j<n;j++){
  80. cout<<z[i][j]<<" ";
  81. }
  82. cout<<endl;
  83.  
  84. }
  85.  
  86. return 0;
  87. }
Success #stdin #stdout 0.01s 5316KB
stdin
4
1
stdout
X=
0 3 9 10 
7 3 9 10 
6 3 1 9 
5 10 8 0 
Y=
1 0 0 0 
0 1 0 0 
0 0 1 0 
0 0 0 1 
Z=
0 3 9 10 
0 0 9 10 
0 0 0 9 
0 0 0 0 
Z=
0 3 9 10 
7 3 9 10 
6 3 1 9 
5 10 8 0