fork download
  1. #include <stdio.h>
  2. void tower(int n,char s,char h,char d){
  3. if (n==0) return;
  4. tower(n-1,s,d,h);
  5. printf("%c→%c\n",s,d);
  6. tower(n-1,h,s,d);
  7. return 0;
  8. }
  9. int main(void) {
  10. int n;
  11. printf("Enter the no. of discs: \n");
  12. scanf("%d",&n);
  13.  
  14. tower(n,'A','B','C');
  15. return 0;
  16. }
Success #stdin #stdout 0.01s 5300KB
stdin
3
stdout
Enter the no. of discs: 
A→C
A→B
C→B
A→C
B→A
B→C
A→C