#include
#include
void hanoi(int x, char from,char to,char aux)
{
if(x==1)
{
printf("Move Disk From %c to %c\n",from,to);
}
else
{
hanoi(x-1,from,aux,to);
printf("Move Disk From %c to %c\n",from,to);
hanoi(x-1,aux,to,from);
}
}
int main(void)
{
int disk;
clrscr();
printf("Enter the number of disks you want to play with:");
scanf("%d",&disk);
double moves=pow(2,disk)-1;
printf("\nThe No of moves required is=%g \n",moves);
hanoi(disk,'A','C','B');
getch();
}
2n-1
010001010001011111100010100010101010111100110011100111000101001100 In binary
Research Towers Of Hanoi http://en.wikipedia.org/wiki/Tower_of_Hanoi You will find your answer
Towers of Hanoi.
Putting a question mark after the name of a game or puzzle does not make it a sensible question.
Here is the algorithm of the algorithm to write an algorithm to access a pointer in a variable. Algorithmically.name_of_the_structure dot name_of_the _field,eg:mystruct.pointerfield
Write an algorithm to find the root of quadratic equation
a write the algorithm to concatenate two given string
It is the "Tower of Hanoi" and it is a puzzle. When you can solve the puzzle you can write the program, when you have learned enough to write simple programs. You do want to be able to write computer programs, don't you?
1. Write mathematical analysis for recursive algorithms. Solve Tower of Hanoi Problem and analyze it.
You don't write an algorithm for a C++ program, unless you are documenting the C++ program after-the-fact. The normal procedure is to write the algorithm first, in a language independent fashion, and then translate that stated algorithm into C++ code, or into whatever language you wish.
This algorithm reads the value of number of discs and prints the move that are to be done for playing towers of hanoi.Pre: n is a positive integer which carries the value of number of discs.Post: prints the moves that are to be done for transferring discs in ascending order in another peg1.initialize value of n(positive integer greater than 1)2.moves = pow(2,disk)-13.if(n=1)i) moves disk from "from" to "to"4. end if5. elsei)hanoi(n-1,from,aux,to)ii) moves disc from "from" to "to''iii) hanoi(n-i,from,aux,to)6.end else7. prints the movesend towers_of_hanoi