X Lecture Capture | My Assignment Tutor

fibonacci_rec(n))X Lecture CaptureX X Sample Midterm: Foundations c. x ® melboume time – Google Search X +5„ 0 G canvas.lms.unimelb.edu.au/courses/107S18/quizzes/109018 ■ I:10 X Aar6,44t:Question 3Not yet graded / 3 ptsWrite a recursive function (int fibonacci_rec(int n)) that returns the nth number in the Fibonacci sequence. The first two values in the sequence are 0 and 1. Each subsequent value is the sum of the previous two values, so the sequence goes as: 0, 1, 1, 2, 3, 5, 8, 13, 21 and so on. Some examples of the returned value of the function is as follows –• fibonacci(8) should return 13; • fibonacci(1) should return 0; • fibonacci(2) should return 1; • fibonacci(10) should return 34;You are not allowed to use any loops in your solution for this question. You should not write a program (with main function) or print any result.Your Answer:*include *includeint fibonacci_rec(int n);int main(int argc, char •argv[]){ int n; if (scanf(“%d”, &n) == 1) { printf(“%dn”,fibonacci_rec(n));return 0;int fibonacci_rec(int n){ if(n ==1) return 0; if(n ==2) return 1; return fibonacci_rec(n-1) + fibonacci_rec(n-2);0 Question 4Correct Answer0 / 1 ptsWhich of the following statements is false?(If you believe multiple answers are false, pick the answer that is furthest from the truth. The test is not designed with “trick questions”.)P Type here to searchO Recursive algorithms are always faster than iterative functions for the same problemTI..ofA faster computer can not improve an algorithm’s complexity C):1 en -17/ 4 J Q)))) ENG 4:10 PM e 31/03/2021 Lei”

QUALITY: 100% ORIGINAL PAPER – NO PLAGIARISM – CUSTOM PAPER

Leave a Reply

Your email address will not be published. Required fields are marked *