Doubt in functtion

##### Title

##### Question

n <- as.integer(readline("enter the number "))

fibonacci <- function(n) {

num1 <-0

num2<-1

for( i in 1:n){

print(num2)

num3 <-num2 +num1

num1 <-num2

num2 <-num3

}

}

fibonacci()

output is:

Error in fibonacci() : argument "n" is missing, with no default

R Functions-in-R 08-09 min 0-10 sec

__Answers:__

Please change the last line of your function as

**fibonacci(n)**one possible solution:

fibo1 = function(num){

f1 = 0

f2 = 1

print(f2)

for(i in 2:num) {

f3= f1 + f2

print(f3)

f1 = f2

f2 = f3

}

}

fibo1(5)

Login to add comment