fork download
  1. #include <stdio.h>
  2.  
  3. int acc(int x){
  4. static int sum=0;
  5. static int count=0;
  6. if(x>=0){
  7. sum+=x;
  8. count++;
  9. return sum;
  10. }
  11. else if(x==-1){
  12. return sum;
  13. }
  14. else if(x==-2){
  15. return count;
  16. }
  17. else{
  18. return -1;
  19. }
  20. }
  21.  
  22. int main(void){
  23. printf("%d\n", acc(3));
  24. printf("%d\n", acc(4));
  25. printf("%d\n", acc(-3));
  26. printf("%d\n", acc(-2));
  27. printf("%d\n", acc(-1));
  28. printf("%d\n", acc(5));
  29. return 0;
  30. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
3
7
-1
2
7
12