fork download
  1. using System;
  2.  
  3. class MatrixMultiplication
  4. {
  5. static void Main()
  6. {
  7. int[,] A = {
  8. {1, 2, 3},
  9. {4, 5, 6},
  10. {7, 8, 9}
  11. };
  12.  
  13. int[,] B = {
  14. {9, 8, 7},
  15. {6, 5, 4},
  16. {3, 2, 1}
  17. };
  18.  
  19. int[,] C = new int[3, 3];
  20.  
  21. // Multiply matrices A × B and store in C
  22. for (int i = 0; i < 3; i++) // O(n)
  23. {
  24. for (int j = 0; j < 3; j++) // O(n)
  25. {
  26. C[i, j] = 0;
  27. for (int k = 0; k < 3; k++) // O(n)
  28. {
  29. C[i, j] += A[i, k] * B[k, j];
  30. }
  31. }
  32. }
  33.  
  34. // Print result
  35. Console.WriteLine("Result of A × B:");
  36. for (int i = 0; i < 3; i++)
  37. {
  38. for (int j = 0; j < 3; j++)
  39. {
  40. Console.Write(C[i, j] + "\t");
  41. }
  42. Console.WriteLine();
  43. }
  44. }
  45. }
  46.  
Success #stdin #stdout 0.06s 28552KB
stdin
45
stdout
Result of A × B:
30	24	18	
84	69	54	
138	114	90