fork download
  1. #include <stdio.h>
  2.  
  3. // ★ ここが指定された形の calculate 関数
  4. void calculate(int (*a)[4])
  5. {
  6. int i, j;
  7. int sum;
  8.  
  9. for (i = 0; i < 3; i++) { // 行番号 0〜2
  10.  
  11. sum = 0; // その行の合計を 0 にする
  12.  
  13. for (j = 0; j < 4; j++) { // 列番号 0〜3
  14. sum = sum + a[i][j]; // 足し算
  15. }
  16.  
  17. printf("行%dの合計 = %d\n", i, sum);
  18. }
  19. }
  20.  
  21. int main(void)
  22. {
  23. // 3行4列の2次元配列を作る
  24. int a[3][4] = {
  25. {1, 2, 3, 4},
  26. {5, 6, 7, 8},
  27. {9, 10, 11, 12}
  28. };
  29.  
  30. // calculate に a を渡して実行!
  31. calculate(a);
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
行0の合計 = 10
行1の合計 = 26
行2の合計 = 42