Recursion Function

Recursion Function

University

30 Qs

quiz-placeholder

Similar activities

PyWars: Compete For Glory

PyWars: Compete For Glory

University

30 Qs

String in C Programming

String in C Programming

University

26 Qs

Stack and Queue

Stack and Queue

University

25 Qs

TechZoom24-BugBash_Prelims

TechZoom24-BugBash_Prelims

University

25 Qs

Java Quiz

Java Quiz

University

25 Qs

Pemrograman Python Quiz ( Session IV - VI)

Pemrograman Python Quiz ( Session IV - VI)

University

33 Qs

 Milking Minds 17-01-24

Milking Minds 17-01-24

University

25 Qs

PYTHON CONTEST

PYTHON CONTEST

University

25 Qs

Recursion Function

Recursion Function

Assessment

Quiz

Computers

University

Hard

Created by

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

Media Image

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

Media Image

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

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?