@chawuciren
2018-10-01T10:03:27.000000Z
字数 447
阅读 679
C语言-VS
#include <stdio.h>
#include <stdlib.h>
/*
Find the nth item of the Fibonacci sequence
*/
int Fib( int n);
int main()//Main function
{
int result = 1,n = 1;
scanf_s("%d", &n);//Enter a n
result=Fib(n);//Call functions
printf("%d", result);//Output result
system("pause");
return 0;
}
int Fib(int n)//Declare function
{
int x = 1;
int y = 1;//Adjacent two
int result = 0;
if(n <= 2)
{
return 1;
}
for (int z = 1; z < n - 1; ++z)//Cycle count nth number
{
result = x + y;
x = y;
y = result;
}
return(result);
}
在此输入正文