程序博客网 > 微信怎样淘宝网卖东西
来源:互联网 发布:微信怎样淘宝网卖东西 编辑:程序博客网 时间:2024/05/17 06:38
应用了递归方法
#include<iostream>//该程序是移动汉诺塔程序using namespace std;int main(){ void hanoi(int n,char one,char two,char three); int m; cout<<"input the number of disks:"; cin>>m; cout<<"The steps of moving"<<m<<"disks:"<<endl; hanoi(m,'A','B','C'); return 0;}void hanoi(int n,char one,char two,char three){ void move(char x,char y); if(n==1) move(one,three); else{hanoi(n-1,one,three,two); move(one,three); hanoi(n-1,two,one,three); }}void move(char x,char y){ cout<<x<<"-->"<<y<<endl;}