Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

File recursive _ functions.c contains an incomplete definition of a function named num _ digits that returns the number of digits in integer n ,

File recursive_functions.c contains an incomplete definition of a function named num_digits
that returns the number of digits in integer n, n >=0. The function prototype is:
SYSC 2006: Foundations of Imperative Programming
10
int num_digits(int n);
If n <10, it has one digit, which is n. Otherwise, it has one more digit than the integer n /10. For
example, 7 has one digit. 63 has two digits, which is one more digit than 63/10(which is 6).
492 has three digits, which is one more digit than 492/10, which is 49.
Define a recursive formulation for num_digits. You'll need a formula for the recursive case
and a formula for the stopping (base) case. Using this formulation, implement num_digits as a
recursive function. (Recall that, in C, if a and b are values of type int, a / b yields an int,
and a % b yields the integer remainder when a is divided by b.) Your num_digits function
cannot have any loops.
Function test_exercise_1 has seven test cases for your num_digits function. It calls
test_num_digits seven times, once for each test case. Notice that test_num_digits has
two arguments: the value that will be passed to num_digits, and the value that a correct
implementation of num_digits will return (the expected result).
Use the console output to help you identify and correct any flaws. Verify that num_digits
passes all of its tests.

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

1. Does your voice project confidence? Authority?

Answered: 1 week ago