Q:

Write a R program to get the first 10 Fibonacci numbers

0

Write a R program to get the first 10 Fibonacci numbers.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Fibonacci <- numeric(10)
Fibonacci[1] <- Fibonacci[2] <- 1
for (i in 3:10) Fibonacci[i] <- Fibonacci[i - 2] + Fibonacci[i - 1]
print("First 10 Fibonacci numbers:")
print(Fibonacci)

Sample Output:

[1] "First 10 Fibonacci numbers:"
 [1]  1  1  2  3  5  8 13 21 34 55

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now