编写函数,求第N个斐波那契数列的值(非递归)
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<Windows.h>
int fibonacci(int n)
{
int first = 1;
int second = 1;
int third = 1;
while(n>2){
third = first + second;
first = second;
second = third;
n--;
}
return third;
}
int main(){
int n = 1;
int i = 1;
printf("请输入你要求的第几个斐波那契数:");
scanf("%d",&n);
i=fibonacci(n);
printf("%d\n", i);
system("pause");
return 0;
}