Social Icons

banner image

tower of hanowi

#include<iostream>
#include<conio.h>
using namespace std;
int towers(int n, char s, char d, char t)
{
if(n==1)
{
cout<<s<<"to"<<d<<"\n";
return 0;
}
towers(n-1,s,t,d);
cout<<s<<"to"<<d<<"\n";
towers(n-1,t,d,s);
}
int main()
{
int n;
cout<<"enter no of disks";
cin>>n;
towers(n,'A','C','B');
}
tower of hanowi tower of hanowi Reviewed by Shobhit Goel on November 07, 2015 Rating: 5

No comments:

Airtel Hackaton 2017

Powered by Blogger.