Fibonacci series program in c
main()
{
int n, i,a=0,b=1,c;
printf("enter the limit of series"):
scanf("%d",&n);
printf("%d,%d", a,b);
for(i=0;i<=n-2;i++)
{
c=a+b;
a=b;
b=c;
printf("%d",c);
}
getch();
}
{
int n, i,a=0,b=1,c;
printf("enter the limit of series"):
scanf("%d",&n);
printf("%d,%d", a,b);
for(i=0;i<=n-2;i++)
{
c=a+b;
a=b;
b=c;
printf("%d",c);
}
getch();
}
Fibonacci series program in c using recursion
#include<stdio.h>
int Fibonacci(int);
main()
{
int n, i = 0, c;
scanf("%d",&n);
printf("Fibonacci series\n");
for ( c = 1 ; c <= n ; c++ )
{
printf("%d\n", Fibonacci(i));
i++;
}
return 0;
}
int Fibonacci(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}
No comments:
Post a Comment