#include
#include
void main()
{
int n,i;
int fib(int);/*Prototype*/
clrscr();
printf("Enter value to Find Fibonacci : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
printf("\n\t%d",fib(i));
getch();
}
int fib(int i)
{
if((i==1)(i==2))
return(1);
else
return(fib(i-1)+fib(i-2));
}
Output
Enter value to Find Fibonacci : 5
1
1
2
3
5
No comments:
Post a Comment