fork download
  1. #include <stdio.h>
  2. #define TRUE 1==1
  3. int main()
  4. { int height, cnt = 0, sum = 0;
  5. while (TRUE) {
  6. printf("入力[%d] = ", cnt + 1);
  7. scanf("%d", &height);
  8. if (height == 0)
  9. break;
  10. sum += height;
  11. cnt++;
  12. }
  13. if (cnt == 0)
  14. cnt = 1;
  15. printf("合計 = %d, 平均 = %d\n", sum, sum / cnt);
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0s 2012KB
stdin
165
170
168
0
stdout
入力[1] = 入力[2] = 入力[3] = 入力[4] = 合計 = 503, 平均 = 167