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