Exercice langage C corrigé tri par insertion avec fonctions

 Exercice 1

1
2
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
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
 
main()
{
 /* Prototypes des fonctions appelées */
 void TRI_INSERTION(int *T, int N);
 void LIRE_TAB (int *TAB, int *N, int NMAX);
 void ECRIRE_TAB (int *TAB, int N);
 /* Variables locales */
 int T[100]; /* Tableau d'entiers */
 int DIM;    /* Dimension du tableau */
 /* Traitements */
 LIRE_TAB (T, &DIM, 100);
 printf("Tableau donné : n");
 ECRIRE_TAB (T, DIM);
 TRI_INSERTION(T, DIM);
  printf("Tableau trié : n");
 ECRIRE_TAB (T, DIM);
 return 0;
}
 
void TRI_INSERTION(int *T, int N)
{
  void INSERER(int X, int *T, int *N);
 /* Variables locales */
 int I;  /* indice courant */
 /* Tri de T par insertion */
 I=1;
 while (I<N)
      INSERER(*(T+I), T, &I);
}
 
void INSERER(int X, int *T, int *N)
{
 . . .
}
 
void LIRE_TAB (int *TAB, int *N, int NMAX)
{
 . . .
}
 
void ECRIRE_TAB (int *TAB, int N)
{
 . . .
}

Exercice 2

1
2
3
4
5
6
7
8
9
10
11
12
13
int RANGER(int *X, int *Y)
{
 int AIDE;
 if (*X>*Y)
     {
      AIDE = *X;
      *X = *Y;
      *Y = AIDE;
      return 1;
      }
 else
     return 0;
 }

Télécharger aussi :

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

1

Besoin d'aide ?