fork download
  1. #include <stdio.h>
  2. int acc(int x){
  3. static int sum=0;
  4. static int count=0;
  5. if(x==-1){
  6. sum=0;
  7. count=0;
  8. return 0;
  9. }
  10. else if(x==-2){
  11. return count;
  12. }
  13. else if(x==0){
  14. return sum;
  15.  
  16. } else {
  17. sum+=x;
  18. count++;
  19. return sum;
  20. }
  21. }
  22. int main(){
  23. int score, num, i;
  24. printf("数字の個数を入力してください");
  25. scanf("%d", &num);
  26. printf("%d\n",num);
  27. for(i=0;i<num;i++){
  28. printf("正の整数を入力してください");
  29. scanf("%d", &score);
  30. printf("%d\n",score);
  31. acc(score);
  32. }
  33. double average = (double)acc(0) / acc(-2);
  34. printf("平均値は%.2fです。\n", average);
  35. return 0;
  36. }
Success #stdin #stdout 0s 5320KB
stdin
2
12
5
stdout
数字の個数を入力してください2
正の整数を入力してください12
正の整数を入力してください5
平均値は8.50です。