fork download
  1. // Let's print out matrix one and matrix 2.
  2.  
  3. // Multiplication My Version
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. void print_matrix(int m[10][10], int s)
  9. /**
  10.  Print out a square matrix of size s, max size 10.
  11.  */
  12. {
  13. for (int i = 0; i < s; ++i)
  14. {
  15. for (int j = 0; j < s; ++j)
  16. {
  17. cout << m[i][j] << "\t";
  18. }
  19. cout << endl;
  20. }
  21. }
  22.  
  23. int main()
  24. {
  25. int m, n, c, d, o, p, first[10][10], second[10][10], mult[10][10];
  26.  
  27. cout << "Enter the number of rows and columns of matrix 1 ";
  28. cin >> m >> n;
  29. cout << "Enter the number of rows and columns of matrix 2 ";
  30. cin >> o >> p;
  31.  
  32. cout << "Enter the elements of first matrix\n";
  33.  
  34. for ( c = 0 ; c < m ; c++ )
  35. {
  36. for ( d = 0 ; d < n ; d++ )
  37. {
  38. cin >> first[c][d];
  39. }
  40. }
  41.  
  42. cout << "Enter the elements of second matrix\n";
  43.  
  44. for ( c = 0 ; c < o ;c++ )
  45. {
  46. for ( d = 0 ; d < p ; d++ )
  47. {
  48. cin >> second[c][d];
  49. }
  50. }
  51. cout << "First Matrix:" << endl;
  52. print_matrix(first, m);
  53. cout << endl << "Second Matrix:" << endl;
  54. print_matrix(second, o);
  55. //mult
  56. /*
  57.   if(n==o)
  58.   {
  59.  
  60.   for ( c = 0 ; c < m ; c++ )
  61.   {
  62.  
  63.   for ( d = 0 ; d < p ; d++ )
  64.   {
  65.   mult[c][d]=0;
  66.  
  67.   for(int k=0;k<n;k++)
  68.   {
  69.  
  70.   mult[c][d] += first[c][k] * second[k][d];
  71.   }
  72.   }
  73.   }
  74.   }
  75.   else {
  76.   cout<<"Multiplication not possible";
  77.   }
  78.   cout << "Product of entered matrices:-\n";
  79.  
  80.   for ( c = 0 ; c < m ; c++ )
  81.   {
  82.   for ( d = 0 ; d < p ; d++ )
  83.   {
  84.   cout << mult[c][d] << "\t";
  85.   }
  86.  
  87.   cout << endl;
  88.   }
  89.  */
  90. return 0;
  91. }
Success #stdin #stdout 0.02s 2728KB
stdin
2
2
3
3
3
3
1
0
0
1
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
First Matrix:
3	3	
1	0	

Second Matrix:
0	1	1011	
0	2273	-1219186208	
2090266759	-1073756048	-1216591463