saving . . . saved how i make function fibonacci (assignment's Q2) has been deleted. how i make function fibonacci (assignment's Q2) has been hidden .
how i make function fibonacci (assignment's Q2)
Title
Question
Create a function which takes a natural number as an argument, and prints Fibonacci series. For example, consider fibonacci(5). It should print the first 5 elements of Fibonacci series, i.e. 1, 1, 2, 3, 5??????

R Functions-in-R 09-10 min 20-30 sec 29-08-21, 2:53 p.m. tanishagoyal

Answers:

You can make use of the following code to create a Fibonacci function -

fibonacci <- function(a)
{
initial = 0
new = 1
for(i in 1:a)
{
update = initial + new
if(i==1)
{
print(1)
}
else
{
print(update)
initial = new
new = update
}}}
31-08-21, 6:26 p.m. chrl3hr5@gmail.com


Log-in to answer to this question.