Implementasi Iteratif Menara Hanoi – Bahasa C

Berikut Source Codenya :
#include //definisi printf,scanf
#include //definisi getch

void hanoi(int n);

int main()
{
int n;
printf(“Input jumlah kepingan : “);
scanf(“%d”,&n);
hanoi(n);
getch();
}

void hanoi(int n)
{
int x;
puts(“”);
for(x=1;x<(1 << n);x++)
printf(“Pindahkan piringan dari %d ke %dn”,(x&x-1)%n + 1,((x|x-1)+1)%n + 1);
}

http://tutorialpemrograman.wordpress.com/category/bahasa-c/

Leave a Reply

Your email address will not be published. Required fields are marked *