Print Friendly and PDF
#include<iostream>
#include<stdio.h>
using namespace std ;
void transfer(int n, char from, char to, char temp);
int main(){
int n;
cout<<"Welcome To The Towers Of Honai\n\n";
cout<<"How many disks? ";
cin>> n;
cout<<"\n";
transfer(n,'L','R','C');
return 0;
}
void transfer(int n, char from, char to, char temp)
{
if(n>0)
{
transfer(n-1, from, temp, to);
printf("Move disk %d from %c to %c\n", n, from, to);
transfer(n-1, temp, to, from);
}
}
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: