
Exercice 1
Écrivez un algorithme permettant de trouver le plus grand entier présent dans un tableau. Vous ferez "tourner à la main" votre algorithme en utilisant le tableau t = [3,5,1,8,4,2].
Voici un algorithme possible (on supposera que la tableau comporte au moins 1 élément):
fonction plus_grand(tab : tableau)
Début
max <-- tab[0]
Pour ind = 1 à nbélément(tab) Faire
Si ( tab[ind] > max ) max <-- tab[ind]
FinPour
Retourner max
Fin
Exercice 2
Écrivez un algorithme permettant de calculer la moyenne de tous les entiers présents dans un tableau. Vous ferez "tourner à la main" votre algorithme en utilisant le tableau t = [3,5,1,8,4,2].
Voici un algorithme possible (on supposera que la tableau comporte au moins 1 élément):
fonction moyenne(tab : tableau)
Début
somme <-- tab[0]
Pour ind = 1 à nbélément(tab) Faire
somme <-- somme+tab[ind]
FinPour
Retourner somme/nbélément(tab)
Fin