⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c2_main.cpp

📁 Essential C++ sample code for VC++ 6.0
💻 CPP
字号:
/**************************************************
 * Essential C++ -- Stanley Lippman
 * Addison-Wesley 
 * ISBN 0-201-48518-4
 * homepage: www.objectwrite.com
 * email: slippman@objectwrite.com
 *************************************************/

#include <iostream>
using namespace std;

bool fibon_elem( int pos, int &elem )
{

	if ( pos <= 0 || pos > 1024 )
	{
		 cerr << "invalid position: " << pos 
			  << " -- cannot handle request!\n";

         elem = 0;
         return false;
	}

    elem = 1; 
    int n_2 = 1, n_1 = 1;
    for ( int ix = 3; ix <= pos; ++ix ) 
    {
		 elem = n_2 + n_1;
		 n_2 = n_1; n_1 = elem;
    }  
	
    return true;
}

bool print_sequence( int pos ) 
{
	if ( pos <= 0 || pos > 1024 ){
		 cerr << "invalid position: " << pos 
			  << " -- cannot handle request!\n";
         return false; 
	}

   cout << "The Fibonacci Sequence for "
        << pos << " positions: \n\t";

   // prints 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -