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