Tour de hanoi avec les pile (stack) langage C
Résolu/Fermé
ghostdz
-
3 mars 2012 à 00:11
hamzastar7 Messages postés 6 Date d'inscription jeudi 3 janvier 2013 Statut Membre Dernière intervention 1 septembre 2013 - 3 janv. 2013 à 23:10
hamzastar7 Messages postés 6 Date d'inscription jeudi 3 janvier 2013 Statut Membre Dernière intervention 1 septembre 2013 - 3 janv. 2013 à 23:10
A voir également:
- Tour de hanoi programme c
- Ce programme est écrit en python. il construit un mot secret dans une variable mais il ne l'affiche pas. modifiez-le pour qu'il affiche le mot secret. exécutez-le. quel est ce mot secret ? ✓ - Forum Python
- Programme demarrage windows 10 - Guide
- Programme (x86) ✓ - Forum Windows
- Programme bonjour ✓ - Forum Windows
- Lg non programmé ✓ - Forum TV & Vidéo
6 réponses
bon la solution sans l utilsation les piles est
#include<stdio.h>
#include<conio.h>
#include<math.h>
void hanoi(int x, char from,char to,char aux)
{
if(x==1)
{
printf("Move Disk From %c to %c\n",from,to);
}
else
{
hanoi(x-1,from,aux,to);
printf("Move Disk From %c to %c\n",from,to);
hanoi(x-1,aux,to,from);
}
}
void main()
{
int disk;
int moves;
printf("Enter the number of disks you want to play with:");
scanf("%d",&disk);
moves=pow(2,disk)-1;
printf("\nThe No of moves required is=%d \n",moves);
hanoi(disk,'A','C','B');
getch();
}
comment utilse les piles dans la solution?
#include<stdio.h>
#include<conio.h>
#include<math.h>
void hanoi(int x, char from,char to,char aux)
{
if(x==1)
{
printf("Move Disk From %c to %c\n",from,to);
}
else
{
hanoi(x-1,from,aux,to);
printf("Move Disk From %c to %c\n",from,to);
hanoi(x-1,aux,to,from);
}
}
void main()
{
int disk;
int moves;
printf("Enter the number of disks you want to play with:");
scanf("%d",&disk);
moves=pow(2,disk)-1;
printf("\nThe No of moves required is=%d \n",moves);
hanoi(disk,'A','C','B');
getch();
}
comment utilse les piles dans la solution?