Friday, 23 September 2016

Towers of Hanoi by recursion

/* Towers of Hanoi by recursion */

#include<stdio.h>
void toh(int,char,char,char);

int main()
{
int n=3;
toh(n,'A','B','C');
return 0;
}

void toh(int n,char a,char b,char c)
{
if(n==1)
printf("\nMoved from %c to %c",a,c);
else
{
toh(n-1,a,c,b);
toh(1,a,' ',c);
toh(n-1,b,a,c);
}
}

No comments:

Post a Comment

Featured post

Country State City Database - MySQL / JSON Download

World Data Bundle — Full Continent, Country, State, City & Currency Dataset This article provides an overview of the  World Geo Data  di...