You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
510 B
44 lines
510 B
#include<stdio.h>
|
|
int Fibon1(int n)
|
|
{
|
|
if (n == 1 || n == 2)
|
|
{
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
return Fibon1(n - 1) + Fibon1(n - 2);
|
|
}
|
|
}
|
|
int main()
|
|
{
|
|
int n = 0;
|
|
int ret = 0;
|
|
scanf("%d", &n);
|
|
ret = Fibon1(n);
|
|
printf("ret=%d", ret);
|
|
return 0;
|
|
}
|
|
|
|
int Fibno2(int n)
|
|
{
|
|
int num1 = 1;
|
|
int num2 = 1;
|
|
int tmp = 0;
|
|
int i = 0;
|
|
if (n < 3)
|
|
{
|
|
return 1;
|
|
}
|
|
else
|
|
{
|
|
for (i = 0; i>n-3; i++)
|
|
{
|
|
tmp = num1 + num2;
|
|
num1 = num2;
|
|
num2 = tmp;
|
|
}
|
|
return tmp;
|
|
}
|
|
}
|