Saturday, March 10, 2012

Write a program to find fibonacci series in c using recursion.

#include
#include
int fiab(int);

void main()
{
int i,n;
clrscr();
printf("How many terms do you wish to find?\n");
scanf("%d",&n);

printf("\nThe Series is : \n");

for(i=1;i<=n;i++)
{
printf(" %d \n",fiab(i));
}

getch();
}

int fiab(int n)
{
if(n==1||n==2){
return 1;}
else{
return(fiab(n-1)+fiab(n-2));}
return 0;
}
 

No comments:

Post a Comment

Sociable