<span style="font-family:Courier New;">#include <stdio.h>
#include <stdlib.h>
static int the_other(int from, int to)
{
int i = 0;
int pos[3] = {0,0,0};
pos[from - 'A'] = 1;
pos[to - 'A'] = 1;
for (i = 0; i < 3; i++)
{
if (pos[i] == 0)
{
return i + 'A';
}
}
}
void hanoi(int n, int from, int to)
{
if (1 == n)
{
printf("move 1 from %c to %c\n", from, to);
return;
}
hanoi(n-1, from, the_other(from, to));
printf("move %d from %c to %c\n", n, from, to);
hanoi(n-1, the_other(from, to), to);
}
int main(int argc, char* argv[])
{
if (argc < 2)
{
printf("Need more arguments!\n");
return -1;
}
hanoi(atoi(argv[1]), 'A', 'C');
return 0;
}
</span>