saving . . . saved assignment on fibbonacci series has been deleted. assignment on fibbonacci series has been hidden .
assignment on fibbonacci series
Title
Question
on giving the following input 

fibbonacci <- function(t1,t2,t3...........tn){
  tn <- 0
  t1=0
  t2=1
  t3=t1+t2
  for(n in t1:tn){
    t(n)=t(n-2)+t(n-1)
  }
  return(tn)
}
fibbonacci(t1,t2,t3.........tn)
the following comments appear-
fibbonacci <- function(t1,t2,t3...........tn){
+   tn <- 0
+   t1=0
+   t2=1
+   t3=t1+t2
+   for(n in t1:tn){
+     t(n)=t(n-2)+t(n-1)
+   }
+   return(tn)
+ }
> fibbonacci(t1,t2,t3.........tn)
Error in t(n) <- t(n - 2) + t(n - 1) : could not find function "t<-"



R Functions-in-R 11-12 min 20-30 sec 14-12-20, 3:36 p.m. Joohi

Answers:

In your case, you have not defined what t means. It would be best if you defined a function first. For instance, you can write the code as given below:


t1 = 0
t2 = 1
count = 2
print(t1)
n <- as.integer(readline("Enter the value of n: "))

if(n == 1){
  print(t1)
} else{
  print(t1)
  print(t2)
  while(count < n){
    nth = t1 + t2
    print(nth)
    t1 = t2
    t2 = nth
    count = count + 1
  }
}

The above-mentioned code is taken from https://www.datamentor.io/r-programming/examples/fibonacci-sequence/

17-12-20, 11:52 p.m. sudhakarst


Log-in to answer to this question.