练习2.1
#include <iostream>
using namespace std;
bool PrintFbl( int Pos, unsigned int &Elem )
{
if ( Pos <= 0 || Pos >= 1024 )
{
cerr << "Error: Pos <= 0 || Pos >= 1024" << endl;
return false;
}
switch ( Pos )
{
case 2: cout << "1 ";
case 1: cout << "1 "; break;
default: cout << "1 1 "; break;
}
int num1 = 1, num2 = 1;
for ( int i = 3; i <= Pos; i++ )
{
Elem = num1 + num2;
num1 = num2;
num2 = Elem;
cout << Elem << ( i % 10 == 0 ? "\n" : " ");
}
cout << endl;
return true;
}
int main()
{
unsigned int E;
int Pos;
while ( cin >> Pos )
{
PrintFbl(Pos, E);
cout << Pos << "的位置上是:" << E << endl;
}
system("pause");
return 0;
}
今天是20200229 好好奇今天过生日的人们明年什么时候过生日啊?😮