Question: Programming in C++ TITLE THREE RECURSIVE FUNCTIONS INTRODUCTION Recursion is a programming technique in which a function calls itself. It is another way of implementing

Programming in C++

TITLE

THREE RECURSIVE FUNCTIONS

INTRODUCTION

Recursion is a programming technique in which a function calls itself. It is another way of implementing repetitive computations, which we have previously associated with loops. When called to solve a problem, a recursive function passes a smaller version (or versions) of the problem to another instance (or instances) of itself, then uses the results returned by the recursive call or calls to build a solution to the original problem.

DESCRIPTION

Design, implement, and document recursive functions to solve three problems; test those functions by calling them from appropriate main functions; and document the functions.

Throughout, keep in mind the three questions that arise in designing a recursive algorithm:

  • What is/are smaller but identical subproblem(s)?
  • How will the smaller solution(s) be used to solve the larger problem?
  • What is/are the base case(s)?

REPORT THE NUMBER OF DIGITS IN AN INTEGER

Write a recursive function numdigs(k) that returns the number of (base 10) digits in its non-negative integer argument.

A run of a program that exercises this function might look like this:

 Enter an integer: 12345 This integer contains 5 digits. 

REVERSE A STRING

Write a recursive function reverse(s,n) that accepts an array s[.] whose initial segment contains n characters and prints out the characters in the segment in reverse order.

A run of a program that exercises this function might look like this:

 Enter a string of characters: abcde98765$A The reversed string is: A$56789edcba 

COMPUTING xn

Write a recursive function exp(x,n) that computes xn for a real value x and a non-negative integer n.

A run of the program that exercises this function might look like this:

 Enter a real value: 14.3 Enter a non-negative integer exponent: 3 14.3 ^ 3 = 2924.207

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!