Saturday, December 5, 2009

FIBONACCI SERIES USING RECURRSION

#include "stdio.h"
#include "conio.h"

long int fib(int); /* Function Prototype */

void main()
{
int n,i;
long int result;
printf("Enter Nth Term : ");
scanf("%d",&n);

i = 0;
while(i < n)
{
result = fib(i++); /* function Call */
printf("%ld\t",result);
}

getch();
}
/* End of Main */

long int fib(int m) /* Function Definition */
{
if (m == 0) /* Control Statements for Recurrsion */
return 0;
else if(m == 1 || m == 2)
return 1;
else
return fib(m-1) + fib(m-2); /* Recursive Statement */
}
/* End of Program */

0 comments:


by Ankit Pokhrel.