fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7. double height;
  8. double total = 0;
  9. int num = 0;
  10.  
  11. while (1) {
  12. printf("身長(0で終了):");
  13. if (scanf("%lf", &height) != 1) {
  14. continue;
  15. }
  16. if (height == 0) break;
  17. total += height;
  18. num++;
  19. }
  20.  
  21. if (0 < num) {
  22. printf("合計=%f\n", total);
  23. printf("平均=%f\n", total / num);
  24. }
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 2056KB
stdin
139
185
0
stdout
身長(0で終了):身長(0で終了):身長(0で終了):合計=324.000000
平均=162.000000