| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 
 |  
#include <stdio.h>
#include <stdlib.h>
 
#define NELEM(a) (sizeof(a)/sizeof *(a))
 
static void affiche (int t[], int size)
{
   int i;
   for (i = 0; i < size; i++)
   {
      printf ("%5d", t[i]);
   }
   printf ("\n");
}
 
static int compare (void const *p1, void const *p2)
{
   int const *n1 = p1;
   int const *n2 = p2;
 
   return *n1 - *n2;
}
 
int main (void)
{
   int tab[] =
   {1, 5, 3, 0, 12, -8, 200, 35, 80, 63};
 
   affiche (tab, NELEM (tab));
   qsort (tab, NELEM (tab), sizeof *tab, compare);
   affiche (tab, NELEM (tab));
 
   return 0;
} | 
Partager