首页 > 代码库 > 练习2014081406

练习2014081406

/********************************************************************* @file     Main_practise.cpp* @date     2014-8-14* @author   Tiger* @brief    练习* @details  试编写一个非递归的函数来计算斐波那契数列Fn,该函数应			能直接计算出每个斐波那契数。上机测试代码的正确性。********************************************************************/#include <iostream>#include <ctime>int main(int argc, const char* argv[]){	srand(static_cast<unsigned int>(time(NULL)));	int n = rand()%5;	int fn_1 = 1, fn_2 = 1, fn = 1;	for (int i=2; i<=n; ++i)	{		fn = fn_1 + fn_2;		fn_2 = fn_1;		fn_1 = fn;	}	std::cout << "第" << n << "项为" << fn << ".\n"; 	system("pause");	return 0;}