Last active
August 29, 2015 14:02
-
-
Save zsrinivas/e69d6f2a753fa71c709a to your computer and use it in GitHub Desktop.
Solution for Towers of Hanoi Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <assert.h> | |
int ia=-1,ib=0,ic=1; | |
void towersofhanoi(int *a,int *b,int *c,int height) | |
{ | |
int temp; | |
if (height>0) | |
{ | |
towersofhanoi(a,c,b,height-1); | |
temp=a[height-1]; | |
a[height-1]=b[height-1]; | |
b[height-1]=temp; | |
towersofhanoi(c,b,a,height-1); | |
} | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
int height,i; | |
int a[100]={0},b[100]={0},c[100]={0}; | |
for (i = 0; i < 100; ++i) | |
a[i]=i+1; | |
scanf("%d", &height); | |
towersofhanoi(a,b,c,height); | |
for (i = 0; i < height; ++i) | |
printf("%d %d %d\n", a[i],b[i],c[i]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment