R Programming: Get the first 10 Fibonacci numbers
R Programming: Basic Exercise-5 with Solution
Write a R program to get the first 10 Fibonacci numbers.
Sample Solution :
R Programming Code :
Fibonacci <- numeric(10) Fibonacci <- Fibonacci <- 1 for (i in 3:10) Fibonacci[i] <- Fibonacci[i - 2] + Fibonacci[i - 1] print("First 10 Fibonacci numbers:") print(Fibonacci)
 "First 10 Fibonacci numbers:"  1 1 2 3 5 8 13 21 34 55
R Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a R program to create a vector which contains 10 random integer values between -50 and +50.
Next: Write a R program to get all prime numbers up to a given number (based on the sieve of Eratosthenes).
Test your Python skills with w3resource's quiz
What is the difficulty level of this exercise?
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework