Contact Learn C
Copy Program Share Program

Program 101:Towers Of Hanoi

Program 101:
#include <stdio.h>
void towerOfHanoi(int,char,char,char);
    int n;
    printf("Enter no of disks\n");
    towerOfHanoi(n, 'A', 'C', 'B');

void towerOfHanoi(int n, char from, char to, char temp)
    if (n == 1)
        printf("Move disk 1 from %c to %c\n", from, to);
    towerOfHanoi(n-1, from, temp, to);
    printf("Move disk %d from %c to %c\n", n, from, to);
    towerOfHanoi(n-1, temp, to, from);

//Coming Soon...


Towers Of Hanoi

No comments:

Post a Comment

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide