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 %d\n”,(x&x-1)%n + 1,((x|x-1)+1)%n + 1);
}

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s