Last active
August 29, 2015 13:56
-
-
Save marwein/8965273 to your computer and use it in GitHub Desktop.
Résolution de la tour de Hanoï recursivement
This file contains 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
/* ************************************************************************** */ | |
/* */ | |
/* ::: :::::::: */ | |
/* 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