Program to format a number with thousands separator in C/C++ Last Updated : 31 Oct, 2020 Comments Improve Suggest changes Like Article Like Report 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. Examples Input: N = 47634Output: 47, 634 Input: N = 1000000Output : 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: C++ // C++ program to implement the // above approach #include <bits/stdc++.h> using namespace std; // Function to put thousands // separators in the given integer string thousandSeparator(int n) { string ans = ""; // Convert the given integer // to equivalent string string num = to_string(n); // Initialise count int count = 0; // Traverse the string in reverse for (int i = num.size() - 1; i >= 0; i--) { count++; ans.push_back(num[i]); // If three characters // are traversed if (count == 3) { ans.push_back(','); count = 0; } } // Reverse the string to get // the desired output reverse(ans.begin(), ans.end()); // If the given string is // less than 1000 if (ans.size() % 4 == 0) { // Remove ',' ans.erase(ans.begin()); } return ans; } // Driver Code int main() { int N = 47634; string s = thousandSeparator(N); cout << s << endl; } Output: 47,634 Time Complexity: O(log10N) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Program to format a number with thousands separator in C/C++ I IshwarGupta Follow Improve Article Tags : Misc Strings Mathematical Computer Science Fundamentals DSA +1 More Practice Tags : MathematicalMiscStrings Similar Reads Program to convert a given number to words | Set 2 Write code to convert a given number into words. Examples: Input: 438237764Output: forty three crore eighty two lakh thirty seven thousand seven hundred and sixty four Input: 999999Output: nine lakh ninety nine thousand nine hundred and ninety nine Input: 1000Output: one thousand Explanation: 1000 i 13 min read Print number with commas as 1000 separators in Python In this program, we need to print the output of a given integer in international place value format and put commas at the appropriate place, from the right. Let's see an example of how to print numbers with commas as thousands of separators in Python.ExamplesInput : 1000000Output : 1,000,000Input : 1 min read Program to convert a given number to words Given a non-negative integer n, the task is to convert the given number into its English representation according to International Number System.Examples:Input: n = 0Output: "Zero"Input: n = 123Output: "One Hundred Twenty Three"Input: n = 10245Output: "Ten Thousand Two Hundred Forty Five"Input: n = 15 min read Program to convert Number in characters Given an Integer N. The task is to convert the number in characters. Examples: Input: N = 74254 Output: Seven four two five four Input: N = 23 Output: Two three An efficient approach: Reverse the number.Iterate through the reversed number from right to left.Extract the last digit by using modulus, t 6 min read Multiples of 3 and 5 without using % operator Write a short program that prints each number from 1 to n on a new line. For each multiple of 3, print "Multiple of 3" instead of the number.For each multiple of 5, print "Multiple of 5" instead of the number.For numbers which are multiples of both 3 and 5, print "Multiple of 3. Multiple of 5." inst 6 min read Like