/* File: hanoi.c
      The towers of hanoi problem
*/

#include <stdio.h>

void move(char from, char to, char aux, int disks) {

   if (disks == 1 )
      printf("Move disk 1 from peg %c to peg %c\n", from, to) ;
   else{
      /* move disks above largest disks to aux peg */
      move(from, aux, to, disks-1) ;

      /* move largest disk to destination peg */
      printf("Move disk %d from peg %c to peg %c\n", disks, from, to) ;

      /* move rest of the disks to destination peg */
      move(aux, to, from, disks-1) ;
   }
} /* function move */


main() {
   int disks, r ;
   
   printf("Enter number of disks: ") ;
   r = scanf("%d", &disks) ;
   if (r < 1 || disks < 1) {
      printf("Need a positive number!\n") ;
      exit() ;
   }

   move('A','C', 'B', disks) ;
}
