fork download
  1.  
  2. #include <stdio.h>
  3.  
  4. void array_mul(int (*x)[2], int (*y)[2], int (*ans)[2]) {
  5.  
  6. for (int i = 0; i < 2; i++) {
  7. for (int j = 0; j < 2; j++) {
  8. ans[i][j] = 0;
  9.  
  10. for (int k = 0; k < 2; k++) {
  11. ans[i][j] += x[i][k] * y[k][j];
  12. }
  13. }
  14. }
  15. }
  16.  
  17. int main(void) {
  18. int x[2][2] = {
  19. {1, 2},
  20. {3, 4}
  21. };
  22.  
  23. int y[2][2] = {
  24. {1, 2},
  25. {3, 4}
  26. };
  27.  
  28. int ans[2][2];
  29.  
  30. array_mul(x, y, ans);
  31.  
  32. printf("結果:\n");
  33. for (int i = 0; i < 2; i++) {
  34. for (int j = 0; j < 2; j++) {
  35. printf("%d ", ans[i][j]);
  36. }
  37. printf("\n");
  38. }
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 5268KB
stdin
Standard input is empty
stdout
結果:
7 10 
15 22