© Éditions Eyrolles
251
Correction des exercices
Exercice 7.2
void maxmin (int t[], int n, int * admax, int * admin)
{ int i, max, min ;
max = t[0] ;
min = t[0] ;
for (i=1 ; i { if (t[i] > max) max = t[i] ;
if (t[i] < min) min = t[i] ;
}
*admax = max ;
*admin = min ;
}
#include
main()
{ void maxmin (int [], int, int *, int *) ;
int t[8] = { 2, 5, 7, 2, 9, 3, 9, 4} ;
int max, min ;
maxmin (t, 8, &max, &min) ;
printf ("valeur maxi : %d\n", max) ;
printf ("valeur mini : %d\n", min) ;
}
Exercice 7.3
void tri (unsigned char c[] , int nc)
{ int i,j ;
char ct ;
for (i=0 ; i for (j=i+1 ; j if ( c[i]>c[j] )
{ ct = c[i] ;
c[i] = c[j] ;
c[j] = ct ;
}
}
Delannoy Livre.book Page 251 Mercredi, 6. mai 2009 4:27 16
Précédent

- 264/281

Suivant