Wednesday, 20 November 2013

Towers of hanoic cprogram

TOWERS OF HANOIC CPROGRAM WITH RECURSION

#include<stdio.h>

void main()

{

int n;

clrscr();

printf("enter no of disks=");

scanf("%d",&n);

towersofhanoi(n,'A','B','C');

getch();

}

int towersofhanoi(int n,char source,char dest,char inter)

{

if(n>=1)

{

towersofhanoi(n-1,source,inter,dest);

printf("\nmove disk from %c to tower %c ",source,dest);

towersofhanoi(n-1,inter,dest,source);

}

}


No comments:

Post a Comment