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