home *** CD-ROM | disk | FTP | other *** search
- /*****************************************
- * hanoi.c --
- * Towers of Hanoi program as in _The Age of Intelligent Machines_
- * by Raymond Kurzweil with main routine written by Sameer Parekh
- * (zane@ddsw1.MCS.COM)
- *****************************************/
-
- void hanoi(original, destination, free, number_of_disks)
- int original, destination, free, number_of_disks;
-
- {
- if (number_of_disks == 1) {
- printf("Move disk 1 from tower %d to tower %d\n", original, destination);
- return;
- }
-
- hanoi(original, free, destination, number_of_disks - 1);
-
- printf("Move disk %d from tower %d to tower %d\n", number_of_disks, original, destination);
-
- hanoi(free, destination, original, number_of_disks - 1);
-
- return;
- }
-
- int main(argc, argv)
- int argc;
- char **argv;
-
- {
- int number;
- if (argc != 2) {
- printf("Usage: %s <number of disks>\n", argv[0]);
- exit(1);
- }
- number = atoi(argv[1]);
-
- if (number < 1) {
- puts("Argument not appropriate!");
- exit(1);
- }
-
- hanoi(1, 2, 3, number);
- }
-
-
-