fork download
  1. #include <stdio.h>
  2.  
  3. void calculate(int (*a)[4]) {
  4.  
  5. const int NUM_ROWS = 3;
  6. const int NUM_COLS = 4;
  7.  
  8. int row_sums[NUM_ROWS];
  9.  
  10. printf("--- 2次元配列の各行の合計結果 ---\n");
  11.  
  12. for (int i = 0; i < NUM_ROWS; i++) {
  13. int current_sum = 0;
  14.  
  15. for (int j = 0; j < NUM_COLS; j++) {
  16.  
  17. current_sum += a[i][j];
  18. }
  19.  
  20. row_sums[i] = current_sum;
  21.  
  22. printf("行 %d の合計 (sum): %d\n", i, row_sums[i]);
  23. }
  24. printf("------------------------------------\n");
  25. }
  26.  
  27. int main() {
  28. int a[3][4] = {
  29. {1, 2, 3, 4},
  30. {5, 6, 7, 8},
  31. {9, 10, 11, 12}
  32. };
  33.  
  34. calculate(a);
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
--- 2次元配列の各行の合計結果 ---
行 0 の合計 (sum): 10
行 1 の合計 (sum): 26
行 2 の合計 (sum): 42
------------------------------------