Program to generating
Fibonocci series using recursion
Program
#include<stdio.h>
void main()
{
int a, b, j;
int fib(int);
printf("\nEnter
N'th Number : "); scanf("%d", &a);
printf("\nPrinting
Values of the Fibonacci Series :\n");
for(j = 0; j < a -
1; j++)
{
b = fib(j);
printf("%d,",
b);
}
}
int fib(int n)
{
int x, y;
if(n == 0 || n == 1)
return (1);
else
{
x = fib(n - 1);
y = fib(n - 2);
return(x + y);
}
}
No comments:
Post a Comment