answersLogoWhite

0

/* hanoi.c */

#include <stdio.h>

#include <stdlib.h>

static long step;

static void Hanoi (int n, int from, int to,int spare)

{

if (n>1) Hanoi (n-1,from,spare,to);

printf ("Step %ld: move #%d %d-->%d\n", ++step, n, from, to);

if (n>1) Hanoi (n-1,spare,to,from);

}

int main (int argc, char **argv)

{

int n;

if (argc==1 (n= atoi(argv[1]))<=0) n= 5;

step= 0;

Hanoi (n, 1, 2, 3);

return 0;

}

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Write an Algorithm for towers of hanoi?

#include#includevoid 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();}


The least number of moves in the tower of hanoi puzzle with five disks?

The number of moves required to solve the Hanoi tower is 2m + 1 . Therefore for a tower of five disks the minimum number of moves required is: 31.


Least number of moves in the tower of hanoi puzzle with five disks?

The number of moves required to solve the Hanoi tower is 2m + 1 . Therefore for a tower of five disks the minimum number of moves required is: 31.


What is the number of moves for 20 disks on the tower of hanoi?

1,048,575 moves and I know because I did the math.


How many moves does it take for the tower of hanoi if it has 52 disks?

100000000


How many moves does it take for the tower of hanoi if it has 7 disks?

127


What is the minimum amount of moves for 64 disks on tower of hanoi?

2^64-1 = 18446744073709551615


Least number of moves in the Tower of Hanoi puzzle with 5 disks?

The least number of moves required to solve the Tower of Hanoi puzzle with 5 disks is calculated using the formula (2^n - 1), where (n) is the number of disks. For 5 disks, this results in (2^5 - 1 = 32 - 1 = 31) moves. Therefore, the minimum number of moves needed is 31.


How do I write a Java program that moves the mouse only when CTRL held and mouse clicked that can run in the background?

You Don't.


How long would it take to the hanoi puzzle with 6 7 8 discs?

For any n-disc version of the Tower of Hanoi, the optimum solution for the puzzle takes a minimum of 2n-1 moves. In the case of 6, 7, 8-sized Towers of Hanoi, the puzzle would take: 26-1 = 63, 27-1 = 127, 28-1 = 255 moves.


What is the link between the number of discs and the minimum moves in the towers of hanoi puzzle and if i was given the number of discs could I work out the minimum moves without doing the puzzle?

If there are N discs, the minimum number of moves required is 2N - 1.


What is the least number of moves in the Tower of Hanoi puzzle with only 5 disks?

To move n disks, you need 2n-1moves. In this case, 31.

Trending Questions
What is the difference between builders and developers? Why do we use robots? Provide three examples of why a project might lack technical feasibilty? What is Object Query Language OQL? Does the current rating of a diode change when it is used in a bridge rectifier EG A bridge made up from four 10 amp diodes would it have a different total current rating. DD? This image shows the direction of the flow of water through a constricted pipe. What happens as you move from position A to position B in the water pipe? Disadvantages of computers to students? What is the allowable stress of steel guaranteed by Chinese standard Q235? What would happen if you used a 19V 3.16Amp power adapter on something that called for a 12V 3Amp power adapter power supply? What is water pressure tunnel? What Is The Name Of The Robot In I Robot? How do you use NetPlay on VirtuaNES? Is Java-script a high level programming language? What is a gene? There are three sources of resistance in a parallel circuit Two of them are rated at 20 ohms the other at 10 ohms What is the circuit's total resistance? Where does the crankshaft breather hose connect on a gy6 motor? What methods and stategies have the teacher in future to ensure that she will able to meet the needs of both high and low achievers in class? What is the consequences of the steamboat? Can a C or CPP program compiled on Linux run on Windows and vice versa assuming that both the OSs are loaded in and can run on the same machine? What are the three views of a sketch or drawing that are required to an object?