A few days ago, I posted the code of Fibonacci Sequence in C by using loop. The following code is written by using Recursion. To get the basic concept about Fibonacci Sequence you can read my previous post.
Previous Post
Let's see the code of Fibonacci Sequence by using recursion...............
#include<stdio.h>
int fibo(int); //prototype declaration
int main()
{
int num, temp, i;
printf("Enter a Number: ");
scanf("%d", &num);
printf("The Fibonacci Sequence is: ");
for(i=0;i<num;i++)
{
printf("%d ", fibo(i));
}
return 0;
}
int fibo(int n)
{
if(n==1||n==0)
{
return n;
}
else
{
return fibo(n-1)+fibo(n-2);
}
}
I've forgotten to post about recursion. I'll post about Recursion very soon. Keep in touch..........
Previous Post
Let's see the code of Fibonacci Sequence by using recursion...............
#include<stdio.h>
int fibo(int); //prototype declaration
int main()
{
int num, temp, i;
printf("Enter a Number: ");
scanf("%d", &num);
printf("The Fibonacci Sequence is: ");
for(i=0;i<num;i++)
{
printf("%d ", fibo(i));
}
return 0;
}
int fibo(int n)
{
if(n==1||n==0)
{
return n;
}
else
{
return fibo(n-1)+fibo(n-2);
}
}
I've forgotten to post about recursion. I'll post about Recursion very soon. Keep in touch..........
0 comments:
Post a Comment