C++ program to implement tower of Hanoi || [PROGRAM AND ALGORITHM]

Tower of Hanoi Executable file link available…,

Tower of Hanoi is a puzzle game of mathematics, tower of Hanoi is a puzzle invented in 1883. Tower of Hanoi puzzle game consists of 3 Tower of different sizes and disk. Which slide into towers.

Algorithm :
1.  Start
Hanoi procedure(disk,source,destination,final)
2.  if disk==1 Then
Move disk from source to destination
Else
3.  Hanoi(disk -1,source,final,destination)
Move disk from disk to destination
4.  Hanoi(disk-1,final,destination,source)
END IF
End Procedure

tower of Hanoi Profram:

#include<iostream>
using namespace std;

void tower(int d, char tower1, char tower2,char tower3)
{

if(d==1)
{
cout<<“shift first disk from towert”<<tower1<<“tto tower”<<tower2<<“nn”;
return;
} // if close here

tower(d-1,tower1,tower3,tower2); // recursive function call
cout<<“shift first disk fromt”<<tower1<<“tto tower”<<tower2<<“n”;

tower(d-1,tower3,tower2,tower1);  //recursive function call
}

int main()
{
int disk;
cout<<“enter the number of disknn”;
cin>>disk;

if(disk<1)
cout<<“there are no disks are shiftednn”;
else
cout<<“there are”<<disk<<“disk in towernn”;

tower(disk,’1′,’2′,’3′);
cout<<“nn”<<disk<<“tdisk in tower 1 are shifted to tower 2”;
return 0;
}

Output:

C++ PROGRAM TO IMPLEMENT STACK USING ARRAY | with executable cpp file

C++ program to find largest of three numbers using inline function

how to install android os to your pc

how to fix there is something wrong

Program to implement bubble sort

INSTALL G++ COMPILER TO LINUX | C++ Compiler | Full installation process with screenshot