-
-
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib>
- #define taille 20
-
- int tableau[taille];
- void init_tableau()
- {
- int L_index;
- randomize();
- for(L_index=0;L_index<taille;L_index++)
- {
- tableau[L_index]=random(100);
- L_index++;
- }
- }
-
- void affiche_tableau()
- {
- int L_index=0;
-
- printf("Voici le tableau\n");
- do
- {
- printf(" %d",tableau[L_index]);
- L_index++;
- }
- while(L_index<taille);
- }
-
- void tri_a_bulles()
- {
- int L_compteur=taille, L_temp;
-
- while(L_compteur>0)
- {
- int L_index=0;
- while(L_index<L_compteur)
- {
- if(tableau[L_index]>tableau[L_index+1])
- {
- L_temp=tableau[L_index+1];
- tableau[L_index+1]=tableau[L_index];
- tableau[L_index]=L_temp;
- }
- L_index++;
- }
- L_compteur--;
- }
- }
-
- void resultat()
- {
- int L_index=0;
-
- printf("\n\nVoici le tableau trie\n");
- do
- {
- printf(" %d",tableau[L_index]);
- L_index++;
- }
- while(L_index<taille);
- }
-
- void main()
- {
- int long L_temps_debut, L_temps_fin, L_temps;
-
- init_tableau();
- affiche_tableau();
- tri_a_bulles();
- resultat();
- getch();
- }
-
#include <conio.h>
#include <stdio.h>
#include <stdlib>
#define taille 20
int tableau[taille];
void init_tableau()
{
int L_index;
randomize();
for(L_index=0;L_index<taille;L_index++)
{
tableau[L_index]=random(100);
L_index++;
}
}
void affiche_tableau()
{
int L_index=0;
printf("Voici le tableau\n");
do
{
printf(" %d",tableau[L_index]);
L_index++;
}
while(L_index<taille);
}
void tri_a_bulles()
{
int L_compteur=taille, L_temp;
while(L_compteur>0)
{
int L_index=0;
while(L_index<L_compteur)
{
if(tableau[L_index]>tableau[L_index+1])
{
L_temp=tableau[L_index+1];
tableau[L_index+1]=tableau[L_index];
tableau[L_index]=L_temp;
}
L_index++;
}
L_compteur--;
}
}
void resultat()
{
int L_index=0;
printf("\n\nVoici le tableau trie\n");
do
{
printf(" %d",tableau[L_index]);
L_index++;
}
while(L_index<taille);
}
void main()
{
int long L_temps_debut, L_temps_fin, L_temps;
init_tableau();
affiche_tableau();
tri_a_bulles();
resultat();
getch();
}