F How we can implement the n-th Fibonacci number in C? | CodeTheta

How we can implement the n-th Fibonacci number in C?

April 21, 2014

This program shows you the N-th Fibonacci number. In this programming code there have a fib function to implement the Fibonacci operation. Program code uses two integer n and r after that fib function uses integer argument and after that it goes in to simple if else loop. In this program the main thing is this:
(fib(n-1)+fib(n-2))
by this mathematical law we can calculate the fiboinacci number of the given of the user defined number.
The output of this programming code is shown in below..

/* http://native-code.blogspot.com */

#include<stdio.h>
#include<conio.h>
int fib(int);
void main()
{
int n, r;
printf("/* http://native-code.blogspot.com */");
printf("\n\nEnter range:\n");
scanf("%d",&n);
r=fib(n);
printf("\nn-th term is: %d", r);
getch();
}
int fib(int n)
{
int s=0;
if(n==1)
return(0);
else if(n==2)
return(1);
else
return(fib(n-1)+fib(n-2));
}

/* http://native-code.blogspot.com */

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us

Post a Comment