> 文档中心 > 斐波那契数列 非递归

斐波那契数列 非递归

#include using namespace std;int feibo(int n){    if(n==1||n==2){ return 1;    }else{ int p=1; int q=1;for (int i = 2; i < n; i++) {   int tmp=p;   p=q;   q=tmp+p;}return q;    }}int main() {cout<<feibo(6);return 0;}