Created
January 22, 2022 22:24
-
-
Save CodeMaster7000/b0c9d3ef202ef7e11fb2c8cd51088116 to your computer and use it in GitHub Desktop.
A program in R that prints the Fibonacci series for as long as you want!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nterms = as.integer(readline(prompt="How many terms should I print? ")) | |
| n1 = 0 | |
| n2 = 1 | |
| count = 2 | |
| if(nterms <= 0) { | |
| print("Plese enter a positive integer") | |
| } else { | |
| if(nterms == 1) { | |
| print("Fibonacci sequence:") | |
| print(n1) | |
| } else { | |
| print("Fibonacci sequence:") | |
| print(n1) | |
| print(n2) | |
| while(count < nterms) { | |
| nth = n1 + n2 | |
| print(nth) | |
| n1 = n2 | |
| n2 = nth | |
| count = count + 1 | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment