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