fork download
  1. #include<iostream>
  2. #include<stdlib.h>
  3. #include<iomanip>
  4. #include<math.h>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. const int N =32;
  11.  
  12.  
  13.  
  14. void initstaticmatrixA( double MatA[][N], int n ) //initialize matrix A
  15. { // regular indexing with 2 indices
  16. for(int i=0; i<n*n; i++)
  17.  
  18. MatA[i/n][i%n]=i;
  19. }
  20.  
  21. void initstaticmatrixB( double MatB[][N], int n ) //initialize matrix B
  22. { // regular indexing with 2 indices
  23. for(int i=0; i<n*n; i++)
  24.  
  25. MatB[i/n][i%n]=i;
  26. }
  27.  
  28. void showMats(double MatA[][N], double MatB[][N],int n) //display matrices A & B
  29. {
  30. int c;
  31. cout<<"Matrix A: Matrix B:"<<endl;
  32. cout<<"------------ ------------"<<endl;
  33. cout<<endl; //regular indexing
  34. for(int r=0; r<n; r++, cout<<endl)
  35. {
  36. for( c=0;c<n;c++)
  37. cout<<setw(4)<<MatA[r][c];
  38. cout<<" ";
  39. for( c=0;c<n;c++)
  40. cout<<setw(4)<<MatB[r][c];
  41. }
  42.  
  43. }
  44.  
  45. void CalculateMatC(double MatA[][N], double MatB[][N], int n) //calculate the product C=A*B
  46. {
  47. int m=n;
  48. double MatC[N][N];
  49. int i, j, k;
  50. for(i=0; i<n; i++)
  51. for(j=0; j<n; j++)
  52. for(MatC[i][j]=k=0; k<n; k++)
  53. MatC[i][j] += MatA[i][k]*MatB[k][j];
  54. showMatC(MatC, m); //Where the problem is!!!!
  55. }
  56.  
  57. void showMatC(double MatC[][N], int n) //show matrix C
  58. {
  59. int c;
  60. cout<<"Matrix C:"<<endl;
  61. cout<<"------------"<<endl;
  62. cout<<endl; //regular indexing
  63. for(int r=0; r<n; r++, cout<<endl)
  64.  
  65. for( c=0;c<n;c++)
  66. cout<<setw(4)<<MatC[r][c];
  67. }
  68.  
  69. int main()
  70. {
  71. const int n=2;
  72. double MatA[N][N], MatB[N][N]; //single
  73. initstaticmatrixA(MatA, n);
  74. initstaticmatrixB(MatB, n);
  75. showMats(MatA,MatB, n);
  76. CalculateMatC( MatA, MatB, n);
  77. cout<<endl<<endl;
  78.  
  79. system("pause");
  80.  
  81. return 0;
  82. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void CalculateMatC(double (*)[32], double (*)[32], int)’:
prog.cpp:54:20: error: ‘showMatC’ was not declared in this scope
    showMatC(MatC, m);     //Where the problem is!!!!
                    ^
stdout
Standard output is empty