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