#include<stdio.h>void move(char x,char y)
{
printf("%c-->%c\n",x,y);
}
void hanoi(int n,char one ,char two,char three)
{
if(n==1) move(one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
main()
{
int m;
printf("input the number of disks:");
scanf("%d",&m);
hanoi(m,'A','B','C');
}
2
#include<stdio.h>void hanoi ( int n, char a, char b, char c )
{ if ( n >= 1 )
{ hanoi ( n-1, a, c, b ) ;
printf("%c --> %c\n", a , c) ;
hanoi ( n-1, b, a, c ) ;
}
}
int main ()
{ int n ;
printf( "Input the number of diskes:\n") ;
scanf( "%d",&n) ;
hanoi ( n, 'A' , 'B' , 'C' ) ;
}