fork(1) download
  1. #include <stdio.h>
  2. void moveOneDisk(int from, int to) {
  3. printf("杭%dから杭%dに移動\n", from, to);
  4. }
  5. void moveDisks(int from, int to , int n) {
  6. int anotherPole = 6-(from+to);
  7. if ( n==0 ) return;
  8. else
  9. moveDisks(from,anotherPole,n-1);
  10. moveOneDisk(from,to);
  11. moveDisks(anotherPole, to, n - 1);
  12.  
  13.  
  14. }
  15. int main(void) {
  16. int n = 1;
  17.  
  18. printf("%d枚の円盤を杭1から杭3に移動させる手順は以下のとおり:\n", n);
  19. moveDisks(1, 3, n);
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1枚の円盤を杭1から杭3に移動させる手順は以下のとおり:
杭1から杭3に移動