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