Write a C Program to Implement Towers of Hanoi









Towers of Hanoi, C Program, Sumit Kar, Timus Rak





#include <stdio.h>



void toh(int,char,char,char);





void main()



{



 int n=3;



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



}





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);



 }







}











Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C