问题九十一:汉诺塔
[plain]
#include <stdio.h>
void hanol(int num, char a, char b, char c);
int main()
{
int num;
char a='A';
char b='B';
char c='C';
printf("please enter a number:");
scanf("%d", &num);
hanol(num, a, b, c);
return 0;
}
void hanol(int num, char a, char b, char c)
{
if(num==1)
{
printf("Move disk %d from %c to %c\n",num, a, c);
}
else
{
hanol(num-1, a, c, b);
printf("Move disk %d from %c to %c\n",num, a, c);
hanol(num-1, b, a, c);
}
}
#include <stdio.h>
void hanol(int num, char a, char b, char c);
int main()
{
int num;
char a='A';
char b='B';
char c='C';
printf("please enter a number:");
scanf("%d", &num);
hanol(num, a, b, c);
return 0;
}
void hanol(int num, char a, char b, char c)
{
if(num==1)
{
printf("Move disk %d from %c to %c\n",num, a, c);
}
else
{
hanol(num-1, a, c, b);
printf("Move disk %d from %c to %c\n",num, a, c);
hanol(num-1, b, a, c);
}
}
补充:软件开发 , C语言 ,