Bhuvan InfoTech Android App

Download our Android App and browse Technical News, Projects, Computer Tricks more easily with lots of Interesting Features.

Tuesday, June 14, 2016

Solve Tower of Hanoi problem | C program

#include <stdio.h>
void hanoifxn(int n, char fr, char tr, char ar)//fr=from rod,tr =to rod, ar=aux rod
{
    if (n == 1)
    {
        printf("\n Move disk 1 from rod %c to rod %c", fr, tr);
        return;
    }
    hanoifxn(n-1, fr, ar, tr);
    printf("\n Move disk %d from rod %c to rod %c", n, fr, tr);
    hanoifxn(n-1, ar, tr, fr);
}

int main()
{
    int n = 4; // n is equal to the number of discs
    hanoifxn(n, 'A', 'C', 'B');  // A, B and C are the name of rod
    return 0;
}
Bhuvan Arora

No comments:

Amazing Deal !