Advertisement
Benlahbib_Abdessamad

Untitled

May 27th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h> //Ne pas oublier d'inclure le fichier time.h
  4.  
  5.  
  6.  
  7. void fillTable(int* tab,int n)
  8.  
  9.     {
  10.        
  11.         int i = 0;
  12.         int nombre_aleatoire = 0;
  13.         for(i=0; i<n; i++)
  14.         {
  15.         nombre_aleatoire = rand();
  16.         tab[i]=nombre_aleatoire;
  17.         }
  18.  
  19.     }
  20.    
  21.  
  22. void sort(int *tab, int n)
  23.  
  24.     {
  25.         int i,j;
  26.         int temp;
  27.         for(i=0;i<n;i++)
  28.             {
  29.                 for(j=i;j<n;j++)
  30.                     {
  31.                         if(tab[i] > tab[j])
  32.                             {
  33.                                 temp=tab[i];
  34.                                 tab[i]=tab[j];
  35.                                 tab[j]=temp;
  36.                             }
  37.                     }
  38.             }
  39.     }
  40.    
  41.    
  42. void afficher(int *tab,int n)
  43.  
  44. {
  45.     int i;
  46.     for(i=0;i<n;i++)
  47.     {
  48.             printf("%d \n",tab[i]);
  49.     }
  50. }
  51.    
  52.    
  53.     int main()
  54. {
  55.     int *tab;int i;int n;
  56.     printf("Inserer la taille :  ");
  57.     scanf("%d",&n);
  58.     tab = malloc (sizeof(int) * n);
  59.     clock_t start = clock();
  60.     // Execuatable code
  61.     printf("Remplissage du tableau .... ! \n ");
  62.     fillTable(tab,n);
  63.     //afficher(tab,n);
  64.     printf("Tri du tableau ... ! \n ");
  65.     sort(tab,n);
  66.     printf("Fin du tri : tableau triΓ©  ! \n ");
  67.     clock_t stop = clock();
  68.     double elapsed = (double)(stop - start) * 1000.0  / CLOCKS_PER_SEC;
  69.     printf("Time elapsed in ms: %f \n", elapsed);
  70.     free(tab);
  71.     system("PAUSE");
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement