#include <bits/stdc++.h>
using namespace std;

int main(){

    int a = 1,b = 1,c = 1;
    int n;cin>>n;

    for(int i = 3;i<=n;i++){
        c = a + b;
        a = b;
        b = c;
    }
    cout<<c;


    return 0;
}

定义三个变量,c为当前项,b为前一项,a为前二项,然后反复迭代就好了

#牛客春招刷题训练营#https://www.nowcoder.com/discuss/727521113110073344