vector
#include <cstdio> #include <iostream> #include <vector> using namespace std; int main(){ int n,min,max; vector<int> number; number.insert(number.end(),0);//尾插法 number.insert(number.end(),0); number.insert(number.end(),1); cin>>n; for(int i = 3;;i++){
//斐波那契数列
number[i] = number[i-2] + number[i-1]; if(number[i] >= n) { max = number[i] == n ? number[i] : number[i-1]; min = number[i]; cout<<"不大于n的最大值是"<< max<<endl; cout<<"不小于n的最小值是"<< min<<endl; break; } } return 0; }