Write a C program which will use recursive functions to find fibonacci sequence
Program Code
#include<stdio.h>
long fibonacci (long n);
int main ()
{
int result,number;
printf("Enter the number\n");
scanf("%d",&number);
result=fibonacci(number);
printf("%1d=%1d",number,result);
return 0;
}
long fibonacci (long n)
{
if(n==0||n==1){
return n;
}
else{
return fibonacci (n-1)+fibonacci (n-2);
}
}
Input
#include<stdio.h>
long fibonacci (long n);
int main ()
{
int result,number;
printf("Enter the number\n");
scanf("%d",&number);
result=fibonacci(number);
printf("%1d=%1d",number,result);
return 0;
}
long fibonacci (long n)
{
if(n==0||n==1){
return n;
}
else{
return fibonacci (n-1)+fibonacci (n-2);
}
}
Input
Output
No comments