fork download
  1. #include <stdio.h>
  2. void cal_array(const int (*x)[3], const int (*y)[3], int (*ans)[3] );
  3. void add(const int (*x)[3], const int (*y)[3], int (*ans)[3]);
  4. void dec(const int (*x)[3], const int (*y)[3], int (*ans)[3]);
  5. void ppp(int (*ans)[3]);
  6.  
  7. int main(void) {
  8.  
  9. const int x[2][3] = { {1,2,3}, {4,5,6} };
  10. const int y[2][3] = { {0,1,2}, {3,4,5} };
  11. int ans[2][3];
  12.  
  13. cal_array(x, y, ans);
  14.  
  15. return 0;
  16. }
  17.  
  18. void add(const int (*x)[3], const int (*y)[3], int (*ans)[3]){
  19.  
  20. printf("加算:\n");
  21.  
  22. for(int i=0; i<2; i++){
  23.  
  24. for(int j=0; j<3; j++)
  25.  
  26. *(ans[i] + j) = *(x[i] + j) + *(y[i] + j);
  27.  
  28. }
  29. }
  30. void dec(const int (*x)[3], const int (*y)[3], int (*ans)[3]){
  31.  
  32. printf("減算:\n");
  33.  
  34. for(int i=0; i<2; i++){
  35.  
  36. for(int j=0; j<3; j++)
  37.  
  38. *(ans[i] + j) = *(x[i] + j) - *(y[i] + j);
  39.  
  40. }
  41. }
  42.  
  43. void cal_array(const int (*x)[3], const int (*y)[3], int (*ans)[3] ){
  44.  
  45. dec(x, y, ans);
  46. ppp(ans);
  47.  
  48. printf("\n");
  49.  
  50. add(x, y, ans);
  51. ppp(ans);
  52. }
  53.  
  54. void ppp(int (*ans)[3]){
  55.  
  56. for(int i=0; i<2; i++){
  57.  
  58. for(int j=0; j<3; j++)
  59.  
  60. printf("%d ", *(ans[i] + j));
  61.  
  62. printf("\n");
  63.  
  64. }
  65. }
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
減算:
1 1 1 
1 1 1 

加算:
1 3 5 
7 9 11