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