Question: Write a recursive function addCommas that expects a non-negative integer (the data type to use is unsigned long long int, which can hold any integer

Write a recursive function addCommas that expects a non-negative integer (the data type to use is unsigned long long int, which can hold any integer up to 19 digits long), returns nothing, and outputs to the screen the number written with commas. For example, addCommas(9008007006) will output to the screen 9,008,007,006. Getting full credit means handling ALL possible input values so that they output correctly - no leading zeroes at the very front, but exactly three digits between commas after that. HINTS: A division operation that stores its result in an int will truncate the result. For example, the statement int n=3754/ / 1000; will result in n being set to the value 3 . Also, remember that the \% operator modulo gives you the remainder of a division. For example, the statement int r=3754%1000; will result in r being set to the value 754 . If you add \#include to your addCommas.cpp file you can make use of these library functions to print a 3-digit number, including leading zeroes for a number with less than three digits. This code has bee tested in CS50 - your IDE may vary! coutsetfill()setw(3)n
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
