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. return ans;
  18. }
  19. else
  20. {
  21. return -1;
  22. }
  23. }
  24. int main(void)
  25. {
  26. printf("%d\n", acc(3));
  27. printf("%d\n", acc(4));
  28. printf("%d\n", acc(-3));
  29. printf("%d\n", acc(-2));
  30. printf("%d\n", acc(-1));
  31. printf("%d\n", acc(5));
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
3
7
-1
0
7
12