fork download
  1. // Multiplication My Version
  2. #include<iostream>
  3.  
  4. using namespace std;
  5. main()
  6. {
  7. int m, n, c, d, o, p, first[10][10], second[10][10], mult[10][10];
  8.  
  9. cout << "Enter the number of rows and columns of matrix 1 ";
  10. cin >> m >> n;
  11. cout << "Enter the number of rows and columns of matrix 2 ";
  12. cin >> o >> p;
  13.  
  14. cout << "Enter the elements of first matrix\n";
  15.  
  16. for ( c = 0 ; c < m ; c++ )
  17. for ( d = 0 ; d < n ; d++ )
  18. cin >> first[c][d];
  19.  
  20. cout << "Enter the elements of second matrix\n";
  21.  
  22. for ( c = 0 ; c < o ;c++ )
  23. for ( d = 0 ; d < p ; d++ )
  24. cin >> second[c][d];
  25. //mult
  26. if(n==o)
  27. {
  28.  
  29. for ( c = 0 ; c < m ; c++ )
  30.  
  31. for ( d = 0 ; d < p ; d++ )
  32. mult[c][d]=0;
  33.  
  34. for(int k=0;k<n;k++)
  35.  
  36. mult[c][d] += first[c][k] * second[k][d];
  37. }
  38. else
  39. cout<<"Multiplication not possible";
  40.  
  41. cout << "Product of entered matrices:-\n";
  42.  
  43. for ( c = 0 ; c < m ; c++ )
  44. {
  45. for ( d = 0 ; d < p ; d++ )
  46. cout << mult[c][d] << "\t";
  47.  
  48. cout << endl;
  49. }
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0.25s 2728KB
stdin
Standard input is empty
stdout
Enter the number of rows and columns of matrix 1 Enter the number of rows and columns of matrix 2 Enter the elements of first matrix
Enter the elements of second matrix
Multiplication not possibleProduct of entered matrices:-