jeudi 5 novembre 2020

How to make fibonacci sequence with if and loop

I have made fibonacci sequence, but now I need to make a serie of the first 10 sequences of fibonacci using for loop and if statement. Can anyone help me with this?

fibo <- function(n){
  if(n<=1){
    return(n)
  } else {
    return(fibo(n-1) + fibo(n-2))
  }
}
print(fibo(10)) 

Aucun commentaire:

Enregistrer un commentaire