-4

For example, if given the number 500000 or 2300000, I need to print it as 500 000 and 2 300 000

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • You can write a loop from the end to the begining of the number, with a counter variable, and each three printed values you print a space and reset the counter. – elcortegano May 09 '17 at 08:55
  • Alternative - you could print numbers with commas separating every 3 using Read more at http://stackoverflow.com/questions/1449805/how-to-format-a-number-from-1123456789-to-1-123-456-789-in-c – Danielius May 09 '17 at 08:56
  • like [this](http://ideone.com/iOYPcM) – BLUEPIXY May 09 '17 at 09:31

1 Answers1

0

If your locale is configured that way and you don't mind limiting your code to POSIX, try the printf ' flag.

setlocale(LC_ALL, "");
printf("%'d\n", 50000);
pmg
  • 106,608
  • 13
  • 126
  • 198