C Program to find Fibonacci Series, Fibonacci Series using Recursion Function in C

C Program to find Fibonacci Series, Fibonacci Series using Recursion Function in C :

Example 1 : How to Write Fibonacci Series using Recursion Function in C with easy logic is given below :-

#include<stdio.h>
#include<conio.h>

fibonacciSeries(int);
void main()
{
int n,r,i;
clrscr();
printf("Enter the number of elements to be printed in Fibonacci Series :");
scanf("%d",&n);
printf("\n");
for(i=0 ; i < n ; i++)
{
r=fibonacciSeries(i);
printf("%d,",r);
}
getch();
}

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

/* if enter 7 then output will be 0,1,1,2,3,5,8, */

Example 2 : How to Write Fibonacci Series in C upto a limit is given below :-

#include<stdio.h>
#include<conio.h>

void main()
{
int n,a=0,b=1,c=0;
clrscr();
printf("Enter a limit :");
scanf("%d",&n);
printf("\n");
for( ;c <= n ; ) /* it means while(c <= n), here for loop does not have first and third part, so it was left blank thats all */
{
printf("%d,",c);
a=b;
b=c;
c=a+b;
}
getch();
}

/* if enter 7 then output will be 0,1,1,2,3,5, */