In C Write a function nthFib that takes an integer argument
In C
Write a function “nthFib” that takes an integer argument N and returns the Nth fibonacci number. You can learn more about the fibonacci series by googling it but the first 10 terms are: 0,1,1,2,3,5,8,13, 21, 34.
Solution
#include<stdio.h>
int nthFib(int N){
if(N<0)
return -1;
else if (N==0)
return 0;
else if (N==1)
return 1;
else if (N>1)
return nthFib(N-1) + nthFib(N-2);
}
int main()
{
int num=nthFib(5); //Change the argument to get different Nth number
printf(\"5th number of Fibonacci series:\",num);
return 0;
}
