Language is C++ In mathematics, the Fibonacci numbers are the series of numbers
ID: 3694102 • Letter: L
Question
Language is C++
In mathematics, the Fibonacci numbers are the series of numbers that exhibit the following pattern: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,... In mathematical notation the sequence Fn of Fibonacci numbers is defined by the following recursive definition: With the initial values of F_0 = 0 and F_1 = 1. Thus, the next number in the series is the sum of the previous two numbers. Write a program that asks the user for a positive integer N and generates the Nth Fibonacci number. Your main function should handle user input and pass that data to a recursive function called Fib that takes an integer value N as input and returns the Nth Fibonacci number.Explanation / Answer
#include<stdio.h>
int fib(int n)
{
if (n <= 1)
return n;
return fib(n-1) + fib(n-2);
}
int main ()
{
int n;
printf("Enter n: ");
scanf("%d", &n);
printf("Nth fibronacci is %d ", fib(n));
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.