Here are a few functions for you to write. Again we'll show a correct
answer and its explanation.
Keep in mind that there are many ways to write correct code,
so your correct answers won't necessarily match these.
This course often requires more than just correct code, but
code that has also been well designed. The explanations will
go into some design issues.
For this exercise, in addition to writing the function described,
you should write a short main() whose sole purpose is to test that
function, passing it appropriate arguments and printing out the
returned value.
A short disposable main() like this is called a driver by
programmers in the field or a test harness by the academic community.
NumDigits()
Doubler()
Doubler() v2.0
Explanation of NumDigits()
Anywhere except in this function.
Remember that a function should do one thing and only one
thing. The job, or function, of this function is to return the
number of digits of a positive integer that has been passed to it.
and add one to the number of digits counted so far, accomplished
by numDigits++;