0% found this document useful (0 votes)
2 views4 pages

PRG Lecture Questions On Recursion

The document outlines three questions related to recursion in C++. Question 1 involves implementing a recursive function based on a given definition, identifying base and general cases, and testing with specific inputs. Questions 2 and 3 require writing recursive functions for summing digits and calculating powers, respectively, along with defining their base and general cases.

Uploaded by

chomboarts
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

PRG Lecture Questions On Recursion

The document outlines three questions related to recursion in C++. Question 1 involves implementing a recursive function based on a given definition, identifying base and general cases, and testing with specific inputs. Questions 2 and 3 require writing recursive functions for summing digits and calculating powers, respectively, along with defining their base and general cases.

Uploaded by

chomboarts
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Questions on Recursion

• The Code implementing all problems (1 – 3)


should be in 1 Program.
• DO NOT CREATE SEPARATE FILES
Question 1
Consider the following recursive definition
Fun(n) = 1, for n = 0;
Fun(n) = 3Fun(n-1) + 2, for n ≥ 1;
• Write a C++ function definition to implement the above recursive definition.
• Identify the base case and the general case
• Test your program for Fun(-5), Fun(3), Fun(1), Fun(15), and for each you should
be able to trace your program
Question 2
Write a recursive function that accepts a number as its
argument and returns the sum of all digits from 1 to the
entered number
Eg if the argument is 5, the function should return the
sum of 5 + 4 + 3 + 2 + 1 which is 15
Step 1: Define your base case and general case
Step 2: write a function definition to implement the cases in
step 1
Question 3
Write a C++ program to implement a
recursive function to calculate the power of
a number.
Step 1: Define your base case and general
case
Step 2: write a function definition to
implement the cases in step 1

You might also like