Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

DISCUSS competency-based pay.

Answered: 1 week ago