C言語なら俺に聞け(入門編)Part 117
■ このスレッドは過去ログ倉庫に格納されています
0612デフォルトの名無しさん
2013/07/25(木) NY:AN:NY.ANhttp://mambo.kuhp.kyoto-u.ac.jp/~masahiro/c/euc/hanoi.c
#include <stdio.h>
#define MAX 256
void hanoi(int n, int from, int to, int use);
main()
{
int n;
char tmp[MAX];
do{
printf("ハノイの塔の円盤の枚数は何枚ですか?1以上の整数で答えて下さい。> ");
fgets(tmp, MAX, stdin);
tmp[MAX - 1] = 0;
n = atoi(tmp);
/* scanf("%d",&n); */
}while(n < 1);
hanoi(n, 1, 2, 3);
}
void hanoi(int n, int from, int to, int use)
{
if(n <= 0) return;
hanoi(n - 1, from, use, to);
printf("円盤%dを棒%dから棒%dに動かす。\n", n, from, to);
hanoi(n - 1, use, to, from);
}
■ このスレッドは過去ログ倉庫に格納されています