Formatted Integer

I solved a problem some day ago. In that problem you had to format an integer. I found it hard to solve. So here I am sharing my problem with you.

Problem:
Read an integer variable and print it in which the digits are separated into groups of three by commas.

Input: 12345678
Output: 12,345,678

Any changes of my code will be appreciated.