saving . . . saved Doubt in functtion has been deleted. Doubt in functtion has been hidden .
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 03-05-20, 5:49 p.m. archana.naware@gmail.com

Answers:

Please change the last line of your function as fibonacci(n)
03-05-20, 8:06 p.m. sudhakarst


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)
12-05-20, 4:24 p.m. suhailalphacs


Log-in to answer to this question.