Untitled
unknown
plain_text
a year ago
635 B
6
Indexable
#include <stdio.h>
// Function hanoi:
// It will print the whole process to move n plates
// from pole begin to pole end.
void hanoi(int n, char begin, char temp, char end) {
// Boundary
if (n == 0) return;
// Recurion
// print some stuff
// Move n-1 plates from begin to temp
hanoi(n-1, begin, end, temp);
// Move n-th plates from begin to end
printf("move disk %d from rod %c to rod %c\n", n, begin, end);
// Move n-1 plates from temp to end
hanoi(n-1, temp, begin, end);
}
int main(){
int n;
scanf("%d", &n);
hanoi(n, 'A', 'B', 'C');
return 0;
}Editor is loading...
Leave a Comment