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