/* * 'Play' Hanoi towers game */ #include int nmoves = 0; void hanoi(int n, char frompeg, char topeg, char auxpeg) { if (n == 1) { printf("Move from %c to %c\n", frompeg, topeg); nmoves += 1; } else { hanoi(n-1, frompeg, auxpeg, topeg); hanoi(1, frompeg, topeg, auxpeg); hanoi(n-1, auxpeg, topeg, frompeg); } } int main(void) { int n = 5; hanoi(n, 'A', 'C', 'B'); printf ("%d moves altogether\n", nmoves); return 0; }