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. {6, 5},
  24. {4, 3},
  25. {2, 1}
  26. };
  27.  
  28. int z[2][2] = {
  29. {10, 6},
  30. {4, 9}
  31. };
  32.  
  33. int ans[2][2];
  34. int i, j;
  35.  
  36. cal_array(x, y, z, ans);
  37.  
  38. printf("計算結果 ans =\n");
  39. for (i = 0; i < 2; i++) {
  40. for (j = 0; j < 2; j++) {
  41. printf("%d ", ans[i][j]);
  42. }
  43. printf("\n");
  44. }
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
計算結果 ans =
30 20 
60 50