bouchnina

trier tableau de caractere ( chaine )

May 24th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. // Page : Langage C
  3. // Link : http://www.facebook.com/MOBY.c00
  4. // JOIN US
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. void main(){
  11.     char chaine[]="xnoadbkie";// chaine non triée
  12.     char tmp;
  13.     int i,test=1;// la variable test pour verifier si le tableau est trié ou pas encore
  14.     do{
  15.         test=0;
  16.         for(i=1;i<strlen(chaine);i++){
  17.             if(chaine[i]<chaine[i-1])
  18.                 {
  19.                 tmp = chaine[i];
  20.                 chaine[i]=chaine[i-1];
  21.                 chaine[i-1]=tmp;
  22.                 test = 1; // On a fait un trie donc on continue la boucle
  23.                 }
  24.         }
  25.     }while(test);
  26. printf("la chaine triée %s\n",chaine);
  27. system("pause");
  28.  
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment