--Originally published at Solving Problems with Programming
PICTURE OF AUTOR
THIS IS THE #QUIZ8 WHOSE OBJECTIVE IS CREATE AND CALL FUNCTIONS TO DO DIFFERENT TASKS AT DIFFERENT TIMES USING RECURSION AND LOOPS. COVERING #MASTERYTOPIC06 #MASTERYTOPIC07 . This IS ALSO to fulfill the #Mastery12 Use of recursion for repetitive algorithms
This #QUIZ08 makes first a survey where I gave some advice or feedback to ken bauer in how i am learning in this course. Next, in this quiz 8 makes a function that calculates and returns the “nth” Fibonacci number where we define a function over the Fibonacci numbers mapping the naturals (starting with zero) to the Fibonacci series.
Link of the picture:Link of the picture
So fibonacci(0) returns 0, fibonacci(1) returns 1, fibonacci(2) returns 1 and so on. Note that we are using the modern definition where the sequence starts with zero. I tried to implement this with two solutions: one with a loop and one with recursion. Which do I think is “better”, which looks more “elegant”, which is more “efficient”?
First let me show you the pictures of the quiz:
FIRST TO DO IN THIS #QUIZ08 with the recursion solution is writing a function called ‘fibonacci(int n)’ with an int parameter called n where this parameter is the value of the list in the serie.
Inside of this function, we have a condition a #Mastery10 use of the if statement. This command allows the condition if the value of n is equal to 0 or 1 when this condition will be true, the tasks inside of the statement will execute. In this case if the value of n is equal than 0 or 1 this will occur:
return n; //With this command you return the value of the int variable n in order to show it in THE MAIN FUNCTION
return n; //With this command you return the value of
Continue reading "#Quiz08 See the algorithm of Fibonacci serie explained!" →