Thursday, September 13, 2012

Recursion Tower of Hanoi


#include <stdio.h>

void move(int n,int A,int C,int B)
 /* number to move, source pole, destination pole and
spare pole respectively */
{
if (n==1)
{
    printf("Move from %d to %d.\n",A,C);}
else     {

    move(n-1,A,B,C);

    move(1,A,C,B);

    move(n-1,B,C,A);
}
}

main()
{
    int n=3;
move(n,1,3,2);
}

1 comment: