(2)Fibonacci数列

来源:互联网 发布:模拟城市我是市长知乎 编辑:程序博客网 时间:2024/05/20 13:06
// sf1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "iostream"using namespace std;void hanno(int n,char A,char B, char C){if(n==1){cout<<"move sheet "<<n<<"from "<<A<<"to "<<C<<endl;}else {hanno(n-1,A,C,B);cout<<"move sheet "<<n<<"from"<<A<<"to"<<C<<endl;hanno(n-1,B,A,C);}}int main(){    int n;cout<<"please input the sheet number:"<<endl;cin>>n;hanno(n,'A','B','C');return 0;}