.bo484849a { font-family: system-ui; margin: 20px; } .titre-centre { text-align: center; } .tableau-484849a { display: flex; justify-content: center; margin: 20px; } .element-484849a { margin: 5px; padding: 10px; border: 1px solid #000; transition: background-color 0.5s; } .trouvé-484849a { background-color: green; color: white; } .vérifié-484849a { background-color: red; } #explication-484849a { margin-top: 20px; line-height: 25px; font-size: 14px; text-align: center; font-family: system-ui; } .exercice-484849a, .solution-484849a { border: 1px solid #000; padding: 10px; margin: 20px; background-color: #f9f9f9; } .bouton-484849a { padding: 10px 20px; cursor: pointer; padding: 7px 10px; text-align: center; cursor: pointer; font-weight: bold; background-color: #d8ffab; border-color: #ccd0d5; color: #8d5064; text-decoration: none; border-radius: 5px; border: 1px solid transparent; } .element-484849a:hover { background-color: lightgray; cursor: pointer; }

Exercice de Recherche Linéaire

Exercice

Vous avez un tableau contenant les éléments suivants : [10, 20, 30, 40, 50].

Essayez de rechercher l\'élément 30 dans le tableau à l\'aide d\'un algorithme de recherche linéaire.

Entrez un nombre à rechercher :

10
20
30
40
50

Solution

Nous allons utiliser une approche simple : parcourir le tableau élément par élément jusqu\'à ce que nous trouvions l\'élément recherché ou atteignions la fin du tableau.

Algorithme de Recherche Linéaire

Fonction Rechercher(T: tableau; n: entier; x: entier): booléen
Début
    Pour i allant de 0 à n-1 faire
        Si T[i] = x alors
            Retourner Vrai
        Fin Si
    Fin Pour
    Retourner Faux
Fin
        

Explication détaillée :

'; ?>