#include <stdio.h>
#include <stdlib.h>
int fib(int);
int main()
{
int num;
int result;
printf("Please enter the number you want in the fibonacci series : ");
scanf("%d", &num);
if (num<0){
printf("You cannot enter a negative number!");
}
else{
result = fib(num);
printf("The %dth number of the fibonacci series is %d", num, result);
}
}
int fib(int n){
if (n==0){
return 0;
}
else if (n==1){
return 1;
}
else{
return(fib(n-1) + fib(n-2));
}
}
#include <stdlib.h>
int fib(int);
int main()
{
int num;
int result;
printf("Please enter the number you want in the fibonacci series : ");
scanf("%d", &num);
if (num<0){
printf("You cannot enter a negative number!");
}
else{
result = fib(num);
printf("The %dth number of the fibonacci series is %d", num, result);
}
}
int fib(int n){
if (n==0){
return 0;
}
else if (n==1){
return 1;
}
else{
return(fib(n-1) + fib(n-2));
}
}
Comments
Post a Comment