Pages

Ads 468x60px

Saturday, 2 June 2012

C Program For FIBANACCI SERIES USING RECURSION


C Program For FIBANACCI SERIES USING RECURSION



Fibonacci series in c programming: c program for Fibonacci series without and with recursion. Using the code below you can print as many number of terms 
of series as desired. Numbers of Fibonacci sequence are known as Fibonacci numbers. First few numbers of series are 0, 1, 1, 2, 3, 5, 8 etc, Except first two terms in sequence every other term is the sum of two previous terms, For example 8 = 3 + 5 (addition of 3, 5). This sequence has many applications in
 mathematics and Computer Science.





CODE:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
printf("Enter the n value:");
scanf("%d",&n);
printf("the fibinacci series is\n");
for(i=0;i<n;i++)
{
printf("%d\n",fib(i));
}
getch();
}
int fib(int n)
{
if(n==0)
{
return(0);
}
if(n==1)
{
return(1);
}
else
{
return(fib(n-1)+fib(n-2));
}
}

0 comments:

Post a Comment

Total Pageviews