fork download
  1. #include <iostream>
  2.  
  3. void printWithComma(int a) {
  4. char s[100];
  5. int i = 0;
  6. while (a > 0) {
  7. s[i++] = a % 10 + 48;
  8. a /= 10;
  9. if (!((i + 1) % 4))
  10. s[i++] = ',';
  11. }
  12. if (!(i % 4))
  13. i--;
  14. for (int j = i - 1; j >= 0; j--)
  15. std::cout << s[j];
  16. std::cout << '\n';
  17. }
  18.  
  19. int main() {
  20. printWithComma(1000000000);
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 4436KB
stdin
Standard input is empty
stdout
1,000,000,000