Question

BONUS (10 pts) Write a function that will find the nth number of the Fibonnaci sequence. The Fibonnaci sequence is 0112 3 58 13 etc. The next number is found by adding the two previous numbers.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

* Writing a C Program to find the nth number of Fibonacci sequence. *

#include<stdio.h>

int sequence(int);

int main()

{

int number;

int answer;

printf("Enter the nth number in the series: ");

scanf("%d", &number);

if(number >= 0)

{

answer = sequence(number);

printf("The %d number iin series is %d\n", number, answer);

}

else

{

printf("Fibonacci of negative numbers is not possible. \n");

}

return 0;

}

int sequence(int number)

{

if (number == 0)

{

return 0;

}

else if (number == 1)

{

return 1;

}

else

{

return(sequence(number-1) + sequence(number-2));

}

}

Sample Output:

Enter the nth number in the series : 12

The 12 number in series is 144.

Add a comment
Know the answer?
Add Answer to:
Write a function that will find the nth number of the Fibonnaci sequence. The Fibonnaci sequence...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using R code only 4. The Fibonacci numbers are the sequence of numbers defined by the...

    Using R code only 4. The Fibonacci numbers are the sequence of numbers defined by the linear recurrence equation Fn F-1 F-2 where F F2 1 and by convention Fo 0. For example, the first 8 Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21. (a) For a given n, compute the nth Fibonnaci number using a for loop (b) For a given n, compute the nth Fibonnaci number using a while loop Print the 15th Fibonacci number...

  • python Write a function that takes as input a single integer parametern and computes the nth...

    python Write a function that takes as input a single integer parametern and computes the nth Fibonacci Sequence number The Fibonacci sequence first two terms are 1 and 1(so, if n - 2 your function should return 1). From there, the previous two values are summed to come up with the next result in the sequence 1.1,2,3,5,8,13, 21, 34, 55, etc.) For example, if the input is 7 then your function should return 13 26561.1615880 1 def Fibonacci(n): # your...

  • 1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci...

    1. (10 points) Write an efficient iterative (i.e., loop-based) function Fibonnaci(n) that returns the nth Fibonnaci number. By definition Fibonnaci(0) is 1, Fibonnaci(1) is 1, Fibonnaci(2) is 2, Fibonnaci(3) is 3, Fibonnaci(4) is 5, and so on. Your function may only use a constant amount of memory (i.e. no auxiliary array). Argue that the running time of the function is Θ(n), i.e. the function is linear in n. 2. (10 points) Order the following functions by growth rate: N, \N,...

  • The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13,...

    The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … The next number is found by adding up the two numbers before it. For example, the 2 is found by adding the two numbers before it (1+1). The 3 is found by adding the two numbers before it (1+2). The 5 is found by adding the two numbers before it (2+3), and so on! Each number in the sequence is called...

  • The Fibonnaci sequence is a recursive sequence defined as: f0 = 1, f1 = 1, and...

    The Fibonnaci sequence is a recursive sequence defined as: f0 = 1, f1 = 1, and fn = fn−1 + fn−2 for n > 1 So the first few terms are 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, . . .. Write a function/procedure/algorithm that computes the sum of all even-valued Fibonnaci terms less than or equal to some positive integer k. For example the sum of all even-valued Fibonnaci terms less than or equal to 40...

  • Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence....

    Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence. Your program should prompt for an integer input n from the user. The program should call a recursive function to compute the nth fibonacci number. Your program must follow programming convention. You should submit program and screenshot of output in a single word/pdf file. You should use following recursive definition of fibonacci function: fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) +fib(n-2)

  • Design a combinational circuit design that given a four-bit number as the input outputs an 8-bit...

    Design a combinational circuit design that given a four-bit number as the input outputs an 8-bit number that represents the nth Fibonacci number in the sequence. For instance, if the input is 0001, the output should be the second number in the Fibonacci sequence. The Fibonacci series looks like the following: 0, 1, 1, 2, 3, 5, 8, 13, and so on. The first two numbers in the sequence are always 0 and 1. However, after that, you must add...

  • A Fibonacci sequence is a series of numbers where the next number in the series is...

    A Fibonacci sequence is a series of numbers where the next number in the series is the sum of the previous two numbers. The sequence starts with the numbers 0 and 1. Here are the first ten numbers of the Fibonacci sequence:             0 1 1 2 3 5 8 13 21 34 Write a Java program to print out the first fifteen numbers of the Fibonacci sequence using a loop. You will need three variables previous, current, and next...

  • Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5,...

    Fibonacci Sequence The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on!         Example: the next number in the sequence above is 21+34 = 55 Source:...

  • Using Java 1. The Fibonacci sequence starts 1, 1, 2, 3, 5, 8, ....Each number in...

    Using Java 1. The Fibonacci sequence starts 1, 1, 2, 3, 5, 8, ....Each number in the sequence (after the first two) is the sum of the previous two. Write a program that computes and outputs the nth Fibonacci number, where n is a value entered by the user. The Fibonacci Sequence 1,1,2,3,5,8,13.21,34,55,89,144,233,377... 1+12 13+2134 1+23 21+34-55 2-35 34+55-09 3+58 56+89144 5+8=13 89+144233 8+13-21 144+233 377 5

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT