《Essential C++》系列笔记之第二章(面向过程的编程风格)之第一节(如何编写函数)

《Essential C++》系列笔记之第二章(面向过程的编程风格)之第一节(如何编写函数)_第1张图片
练习2.1

#include 
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 好好奇今天过生日的人们明年什么时候过生日啊?

你可能感兴趣的:(《Essential,C++》系列笔记)