Exercice algorithme corrigé les fonctions (Min, Max)

1) Ecrire une fonction max3 qui retourne le maximum de trois entiers

Fonction : max3(a, b, c : entier) : entier :

Var : max3 : entier

Début : Si a>b alors

Si a>c alors max3 <= a

Sinon max3 <= c

Sinon

Si c>b alors max3 <= c

Sinon max3 <= b

Retourner (max3)

Fin

2) Ecrire une fonction min3 qui retourne le minimum de trois entiers

Fonction : min3(a, b, c : entier ) : entier :

Var min3 : entier

Début

Retourner (–max3(-a, -b, -c))

Fin

3) Ecrire une fonction max2 qui retourne le maximum de deux entiers

Fonction : max2 (a, b : entier) : entier

Var : max2 : entier

Début : Si a

Sinon max2 <= a

Retourner (max2)

Fin

4) Ecrire une fonction max3 qui retourne le maximum de trois entiers en faisant appel à max2

Fonction : max3 (a, b, c : entier) : entier :

Var : max3 : entier

Début : max3 <= max2 [max2 (a, b), c)

Retourner (max3)

Fin

Télécharger aussi :

Laisser un commentaire

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