Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h> //Ne pas oublier d'inclure le fichier time.h
- void fillTable(int* tab,int n)
- {
- int i = 0;
- int nombre_aleatoire = 0;
- for(i=0; i<n; i++)
- {
- nombre_aleatoire = rand();
- tab[i]=nombre_aleatoire;
- }
- }
- void sort(int *tab, int n)
- {
- int i,j;
- int temp;
- for(i=0;i<n;i++)
- {
- for(j=i;j<n;j++)
- {
- if(tab[i] > tab[j])
- {
- temp=tab[i];
- tab[i]=tab[j];
- tab[j]=temp;
- }
- }
- }
- }
- void afficher(int *tab,int n)
- {
- int i;
- for(i=0;i<n;i++)
- {
- printf("%d \n",tab[i]);
- }
- }
- int main()
- {
- int *tab;int i;int n;
- printf("Inserer la taille : ");
- scanf("%d",&n);
- tab = malloc (sizeof(int) * n);
- clock_t start = clock();
- // Execuatable code
- printf("Remplissage du tableau .... ! \n ");
- fillTable(tab,n);
- //afficher(tab,n);
- printf("Tri du tableau ... ! \n ");
- sort(tab,n);
- printf("Fin du tri : tableau triΓ© ! \n ");
- clock_t stop = clock();
- double elapsed = (double)(stop - start) * 1000.0 / CLOCKS_PER_SEC;
- printf("Time elapsed in ms: %f \n", elapsed);
- free(tab);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement