fork download
  1. #include <stdio.h>
  2.  
  3. void g(int n, int c)
  4. {
  5. if (n < 0)printf("-"),n *= -1;
  6. if (n / 10)g(n / 10, c + 1);
  7. printf("%d", n % 10);
  8. if (c && (c % 3 == 0) && (n))printf(",");
  9. }
  10.  
  11. void f(int n)
  12. {
  13. g(n, 0),printf("\n");
  14. }
  15. int main()
  16. {
  17. f(-1234567);
  18. f(-1234);
  19. f(-1);
  20. f(-0);
  21. f(1234567);
  22. f(1234);
  23. f(1);
  24. f(0);
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
-1,234,567
-1,234
-1
0
1,234,567
1,234
1
0