FIBONACCI SERIES USING RECURSION
FIBONACCI SERIES USING RECURSION
INPUT
#include <stdio.h>
int fib(int);
int main()
{
int n, i=0, f;
printf("Enter te number of terms you want in the series\n");
scanf("%d", &n);
for (f = 1; f <= n; f++)
{
printf("%d\n", fib(i));
i++;
}
return 0;
}
int fib(int n)
{
if (n == 0 || n == 1)
{
return n;
}
else
{
return (fib(n - 1) + fib(n - 2));
}
}
OUTPUT
Enter te number of terms you want in the series
5
0
1
1
2
3
Comments
Post a Comment