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