Skip to content

Instantly share code, notes, and snippets.

@marwein
Last active August 29, 2015 13:56
Show Gist options
  • Save marwein/8965273 to your computer and use it in GitHub Desktop.
Save marwein/8965273 to your computer and use it in GitHub Desktop.
Résolution de la tour de Hanoï recursivement
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hanoi_recursive.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbouallo <mbouallo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/02/12 21:43:17 by mbouallo #+# #+# */
/* Updated: 2014/02/12 21:45:52 by mbouallo ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
void Hanoi(int n, char x, char y, char z)
{
if (n>0)
{
Hanoi(n - 1, x, z, y);
printf("\n%c -> %c", x, y);
Hanoi(n - 1, z, y, x);
}
}
int main(void)
{
int n;
printf("Combien de Disques ? : ");
scanf("%d", &n);
Hanoi(n, 'A', 'B', 'C');
printf("\n");
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment