
Recursion Function

Quiz
•
Computers
•
University
•
Hard
Nursyahirah Tarmizi
Used 1+ times
FREE Resource
30 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Which of the following is the best definition of a RECURSIVE method?
A method that iterates itself exactly 5 times.
A method that cannot be called more than once.
A method that invokes itself by name within the method.
A method that will never iterate infinitely.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Every line in a C program should end with a _______
;
:
,
.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Commonly used input function is _____
scanf()
printf()
total()
above all
4.
FILL IN THE BLANK QUESTION
1 min • 2 pts
The process in which a function calls itself directly or indirectly is called _______
5.
FILL IN THE BLANK QUESTION
1 min • 2 pts
The method copies the address of an argument/ parameter into the formal parameter is call by ______
6.
MULTIPLE CHOICE QUESTION
45 sec • 1 pt
The code given shows a function namely print_message to print out a message. The code in red box is a function declaration which is also known as function ______
function prototype
function call
function definition
above all
7.
MULTIPLE CHOICE QUESTION
1 min • 2 pts
Guess the output?
3
18
6
Error
Answer explanation
The recursion case defined in the nSum() function of the above example is:
int res = n + nSum(n - 1)
The base condition defined for nSum() function is:
if (n = = 0) {
return 0;
}
In the nSum() function, Recursive Case is:
int res = n + nSum(n - 1);
In the program, n = 3, so as nSum(3)'s recursive case, we get:
int res = 3 + nSum(2);
In nSum(2), the recursion case will be the same, but n = 2, so nSum(2) will be:
int res = 2 + nSum(1);
Similarly, for nSum1:
int res = 1 + nSum(0);
As such, for nSum(3), we get:
int res = 3 + 2 + 1 + nSum(0);
As the base condition is n == 0, nSum(0) will return 0.
So the recursion will stop here and the final value returned by the function will be:
int res = 3 + 2 + 1 + 0;
= 0
Create a free account and access millions of resources
Similar Resources on Wayground
25 questions
Code Carnival

Quiz
•
University
25 questions
Python Programming Basics 1

Quiz
•
University
30 questions
conditions function in python

Quiz
•
University
25 questions
Introduction to Computers

Quiz
•
University
25 questions
Programming Skills C/C++

Quiz
•
University
30 questions
OODP FT1 Assessment Questions

Quiz
•
University
25 questions
PYTHON CONTERST 3

Quiz
•
University
25 questions
Basic C Programming

Quiz
•
University
Popular Resources on Wayground
10 questions
Video Games

Quiz
•
6th - 12th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
10 questions
UPDATED FOREST Kindness 9-22

Lesson
•
9th - 12th Grade
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
20 questions
US Constitution Quiz

Quiz
•
11th Grade
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
10 questions
Would you rather...

Quiz
•
KG - University
20 questions
Definite and Indefinite Articles in Spanish (Avancemos)

Quiz
•
8th Grade - University
7 questions
Force and Motion

Interactive video
•
4th Grade - University
10 questions
The Constitution, the Articles, and Federalism Crash Course US History

Interactive video
•
11th Grade - University
7 questions
Figurative Language: Idioms, Similes, and Metaphors

Interactive video
•
4th Grade - University
20 questions
Levels of Measurements

Quiz
•
11th Grade - University
16 questions
Water Modeling Activity

Lesson
•
11th Grade - University
10 questions
ACT English prep

Quiz
•
9th Grade - University