Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void solveTowers(int count1, char source, char destination, char spare) {
- if (count1 == 1) {
- printf("Move # %d disk from pole %c to pole %c\n",count1,source,destination,spare);
- }
- else {
- solveTowers(count1-1, source, spare, destination);
- printf("Move # %d disk from pole %c to pole %c\n",count1,source,destination,spare);
- solveTowers(count1-1, spare, destination, source);
- }
- }
- int main(){
- int n;
- scanf("%d",&n);
- solveTowers(n,'a','c','b');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement