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