fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int matrix1[3][3], matrix2[3][3], result[3][3];
  6.  
  7. cout << "Enter elements of first 3x3 matrix:\n";
  8. for (int i = 0; i < 3; i++) {
  9. for (int j = 0; j < 3; j++) {
  10. cin >> matrix1[i][j];
  11. }
  12. }
  13.  
  14. cout << "Enter elements of second 3x3 matrix:\n";
  15. for (int i = 0; i < 3; i++) {
  16. for (int j = 0; j < 3; j++) {
  17. cin >> matrix2[i][j];
  18. }
  19. }
  20.  
  21. // Adding matrices
  22. for (int i = 0; i < 3; i++) {
  23. for (int j = 0; j < 3; j++) {
  24. result[i][j] = matrix1[i][j] + matrix2[i][j];
  25. }
  26. }
  27.  
  28. cout << "Resultant matrix after addition:\n";
  29. for (int i = 0; i < 3; i++) {
  30. for (int j = 0; j < 3; j++) {
  31. cout << result[i][j] << " ";
  32. }
  33. cout << endl;
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Enter elements of first 3x3 matrix:
Enter elements of second 3x3 matrix:
Resultant matrix after addition:
-696459704 10562 -697670944 
10562 1799324575 5281 
-699407192 10562 -697670224