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