Showing posts with label Hanoi of Series in C. Show all posts
Showing posts with label Hanoi of Series in C. Show all posts

Monday, 23 February 2015

Hanoi of Series in C


#include <stdio.h>
void hanoi(int num_disks,char *SRC,char *TMP,char *TRGT);
void main(void)
{
int discs;
char SOURCE[10],TEMP[10],TARGET[10];
printf("\n How Many Discs ?");
scanf("%d",&discs);
printf("\n Source Peg is   ?");
scanf("%s",SOURCE);
printf("\n Target Peg is   ?");
scanf("%s",TARGET);
printf("Intermediate peg is ?");
scanf("%s",TEMP);
printf("\n");
hanoi(discs,SOURCE,TEMP,TARGET);
}
void hanoi(int num_discs,char *A,char *B,char *C)
{
if(num_discs==1)
printf("\n Move Disc From     %s             to               %s\n",A,C);
else
{
hanoi(num_discs-1,A,C,B);
printf("Move Disc From %s to %s\n",A,C);
hanoi(num_discs-1,B,A,C);
}
}