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