fork download
  1.  
  2. #include <stdio.h>
  3. int acc(int x){
  4. static int sum=0;
  5. static int count=0;
  6. if(x>=0)
  7. {
  8. sum+=x;
  9. count++;
  10. return sum;
  11. }
  12. else if(x==-1)
  13. {
  14. return sum;
  15. }
  16. else if(x==-2)
  17. {
  18. return count;
  19. }
  20. else
  21. {
  22. return -1;
  23. }
  24. }
  25. int main(void) {
  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. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
3
7
-1
2
7
12