
Recursion Function
Authored by Nursyahirah Tarmizi
Computers
University
Used 1+ times

AI Actions
Add similar questions
Adjust reading levels
Convert to real-world scenario
Translate activity
More...
Content View
Student View
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
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
25 questions
Quiz No. 1 - Functions in JavaScript
Quiz
•
University
25 questions
AI 900 - pt 5
Quiz
•
University
25 questions
Профессиональная иностранная терминология_3
Quiz
•
University
25 questions
Java Review
Quiz
•
9th Grade - University
25 questions
Machine Learning (Concept Learning)
Quiz
•
University
25 questions
Quiz kotajako1
Quiz
•
University
25 questions
Information and Technology Finals
Quiz
•
University
25 questions
MYSQL QUIZ 1
Quiz
•
University
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade