Skip to content

Instantly share code, notes, and snippets.

@CodeMaster7000
Created January 22, 2022 22:24
Show Gist options
  • Select an option

  • Save CodeMaster7000/b0c9d3ef202ef7e11fb2c8cd51088116 to your computer and use it in GitHub Desktop.

Select an option

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!
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