fork download
  1. //
  2. // main.cpp
  3. // Matrix multiplication
  4. //
  5. // Created by Himanshu on 17/09/21.
  6. //
  7.  
  8. #include <iostream>
  9. using namespace std;
  10. const int N = 2, M = 2;
  11.  
  12. void multiplyMatrices (int A[N][M], int B[N][M]) {
  13. int C[N][M];
  14.  
  15. for (int i=0; i<N; i++) {
  16. for (int j=0; j<M; j++) {
  17. C[i][j] = 0;
  18. for (int k=0; k<N; k++) {
  19. C[i][j] += A[i][k]*B[k][j];
  20. }
  21. }
  22. }
  23.  
  24. cout<<"Multiplcation of Matrices A and B:"<<endl;
  25.  
  26. for (int i=0; i<N; i++) {
  27. for (int j=0; j<M; j++) {
  28. cout<<C[i][j]<<" ";
  29. }
  30. cout<<endl;
  31. }
  32.  
  33.  
  34. }
  35.  
  36. int main() {
  37. int A[N][M] = {{1, 2}, {3, 4}};
  38. int B[N][M] = {{5, 6}, {7, 8}};
  39.  
  40. multiplyMatrices(A, B);
  41. }
  42.  
Success #stdin #stdout 0s 5464KB
stdin
Standard input is empty
stdout
Multiplcation of Matrices A and B:
19 22 
43 50