fork download
  1. #include <stdio.h>
  2.  
  3. void calculate( int (*a)[4], int rows );
  4.  
  5. int main(void)
  6. {
  7. int a[3][4] = {
  8. {1,2,3,4},
  9. {5,6,7,8},
  10. {9,10,11,12}
  11. };
  12.  
  13. int rows = sizeof(a) / sizeof(a[0]);
  14.  
  15. calculate(a, rows);
  16.  
  17. return 0;
  18. }
  19.  
  20. void calculate( int (*a)[4], int rows)
  21. {
  22. int sum[rows];
  23.  
  24. for(int i=0; i<rows; i++){
  25. int add = 0;
  26. for(int j=0; j < 4; j++){
  27. add += a[i][j];
  28. }
  29. sum[i] = add;
  30. }
  31.  
  32. for(int i=0; i<rows; i++)
  33. {
  34. printf("%d行目の合計の計算結果は%d \n", i, sum[i] );
  35. }
  36. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
0行目の合計の計算結果は10 
1行目の合計の計算結果は26 
2行目の合計の計算結果は42