Advertisement
Dragonkoko

Hanoi's Towers

Jan 19th, 2014
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include<stdio.h>
  2. void solveTowers(int count1, char source, char destination, char spare) {
  3.     if (count1 == 1) {
  4.         printf("Move # %d  disk from pole %c to pole %c\n",count1,source,destination,spare);
  5.     }
  6.     else {
  7.         solveTowers(count1-1, source, spare, destination);
  8.         printf("Move # %d disk from pole %c to pole %c\n",count1,source,destination,spare);
  9.         solveTowers(count1-1, spare, destination, source);
  10.     }
  11. }
  12. int main(){
  13.     int n;
  14.     scanf("%d",&n);
  15.     solveTowers(n,'a','c','b');
  16.     return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement