Advertisement
Guest User

ordonner_tableau/amine

a guest
Jul 4th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. void ordonnerTableau(int tableau[], int tailleTableau);
  5.  
  6. int main(){
  7.     int tableau[5];
  8.     tableau[0]=30;
  9.     tableau[2]=22;
  10.     tableau[1]=18;
  11.     tableau[3]=35;
  12.     tableau[4]=12;
  13.    
  14.     printf("Le tableau avant ordonner: ");
  15.     for(int i=0;i<5;i++){
  16.         printf("\ntableau[%d] = %d",i,tableau[i]);
  17.     }
  18.    
  19.     ordonnerTableau(tableau,5);
  20.    
  21.     printf("\n\nLe tableau apres ordonner: ");
  22.    
  23.     for(int i=0;i<5;i++){
  24.         printf("\ntableau[%d] = %d",i,tableau[i]);
  25.     }
  26.    
  27.     return 0;
  28. }
  29.  
  30. void ordonnerTableau(int tableau[], int tailleTableau){
  31.     int var_pt;
  32.     for(int i=0;i<5;i++){
  33.         for(int j=0;j<5;j++){
  34.             if(tableau[i]<tableau[j]){
  35.                 var_pt=tableau[i];
  36.                 tableau[i]=tableau[j];
  37.                 tableau[j]=var_pt;
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement