Given an integer N, the task is to print output of the given integer in international place value format and put commas at the appropriate place, from the right.
Input: N = 47634
Output: 47, 634
Input: N = 1000000
Output : 1, 000, 000
Approach: Follow the steps below to solve the problem:
- Convert the given integer N to its equivalent string.
- Iterate over the characters of the given string from the right to the left.
- After traversing every 3 characters, insert a ‘,’ separator.
Below is the implementation of the above approach:
Time Complexity: O(log10N)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.