Skip to content

Instantly share code, notes, and snippets.

@kimitoboku
Created May 8, 2014 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimitoboku/63d2960efd2cf5e402dc to your computer and use it in GitHub Desktop.
Save kimitoboku/63d2960efd2cf5e402dc to your computer and use it in GitHub Desktop.
hanoi
#include<stdio.h>
void hanoi(int n,char a,char b,char c){
if(n>0){
hanoi(n-1,a,b,c);
printf("一番上を%cから%cに移動\n",a,b);
hanoi(n-1,b,c,a);
}
}
int main(void){
int n;
printf("何段の塔を行うか入力して下さい:");
scanf("%d",&n);
hanoi(n,'A','B','C');
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment