how i make function fibonacci (assignment's Q2)

##### Title

##### Question

Create a function which takes a natural number as an argument, and prints Fibonacci series. For example, consider fibonacci(5). It should print the first 5 elements of Fibonacci series, i.e. 1, 1, 2, 3, 5??????

R Functions-in-R 09-10 min 20-30 sec

__Answers:__

You can make use of the following code to create a Fibonacci function -

fibonacci <- function(a)

{initial = 0

new = 1

for(i in 1:a)

{

update = initial + new

if(i==1)

{

print(1)

}

else

{

print(update)

initial = new

new = update

}}}

Login to add comment