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