可以从键盘输入一个数来指定数组的值吗
#include<iostream>#include<iomanip>
using namespace std;
void main()
{
int n;
cin>>n;
int F[n];
F[1]=1;
F[2]=1;
int i;
for(i=3;i<n;i++)
F[i]=(F[i-1]+F[i-2])%1007;
cout<<setw(15)<<F[i]<<endl;
return;
}
#include <iostream> #include <iomanip> #include <vector> using namespace std; int main( void ) { size_t n; cin >> n; vector<int> F( n, 0 ); if( F.size() > 0 ) F[0] = 1; if( F.size() > 1 ) F[1] = 1; for( size_t i=2; i<n; ++i ) F[i] = (F[i-1]+F[i-2])%1007; if( !F.empty() ) cout << setw(15) << F.back() <<endl; return 0; }
#include <iostream> #include <iomanip> #include <vector> using namespace std; int main( void ) { unsigned n; cin >> n; unsigned a = 1; unsigned b = 0; for( unsigned i=0; i!=n%108; ++i ) // n%108 是因为每108次为一个相同序列的循环 { unsigned c = (a+b)%1007; a = b; b = c; } cout << b << endl; return 0; }