作者在 2012-10-28 15:23:06 发布以下内容
//:hanoi典型的递归调用
#include <stdio.h>
void hanoi(int n, char a, char b, char c);
void move(char a, char b);
int main(){
int n;
printf("input an unsigned integer:");
scanf_s("%d", &n);
printf("========game begin========n");
hanoi(n, 'A', 'B', 'C');
return 0;
}
void hanoi(int n, char a, char b, char c){
if(1==n){
move(a, c);
}else{
hanoi(n-1, a, c, b);
move(a, c);
hanoi(n-1, b, a, c);
}
}
void move(char a, char b){
printf("%c ---> %cn", a, b);
}
#include <stdio.h>
void hanoi(int n, char a, char b, char c);
void move(char a, char b);
int main(){
int n;
printf("input an unsigned integer:");
scanf_s("%d", &n);
printf("========game begin========n");
hanoi(n, 'A', 'B', 'C');
return 0;
}
void hanoi(int n, char a, char b, char c){
if(1==n){
move(a, c);
}else{
hanoi(n-1, a, c, b);
move(a, c);
hanoi(n-1, b, a, c);
}
}
void move(char a, char b){
printf("%c ---> %cn", a, b);
}