Friday, October 28, 2022

Tower of Hanoi 'C' Code

// Tower of Hanoi 

#include <stdio.h>

void tower(int,char,char,char);

int main()

{

    char A='A',B='B',C='C';

    int n;

    

    printf("Enter the number of disks");

    scanf("%d",&n);

    

    tower(n,A,B,C);


    return 0;

}

void tower(int n,char A,char B,char C)

{

    if(n!=0)

    {

        tower(n-1,A,C,B);

        printf("\nMove Disk from %c -> %c",A,C);

        tower(n-1,B,A,C);

    }

}

No comments:

Post a Comment