I'm trying to find the highest Fibonacci number before 5000. this is the code I have so far:
n <- 5000
fib <- c()
fib[1] <- 1
fib[2] <- 1
c <- 1
i <- 3
repeat {
fib[i] <- fib[i-1] + fib[i-2]
i <- i+1
c <- c+1
if (fib[i]>=5000) {
break
}
h <- fib[c]
print(h)
}
The error I receive is:
Error in if (fib[i] >= 5000) { : missing value where TRUE/FALSE needed
Any thoughts on how to resolve? I know my code isn't perfect, but I'm learning :)