Files
CITISE1/IUT/Info1/TD/Exercices/10.5_tableau_boucle/10.5.txt
2026-04-08 20:11:20 +02:00

123 lines
4.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{Fonction 1
R : copier les élements dun tableau dentiers dans un autre.
E : tab_in un tableau d'entiers, taille_pratique_in un entier, taille_réele_out
E/S : tab_out un tableau d'entiers
S : Vide}
copy : une fonction(tab_in : un tableau d'entiers,
taille_pratique_in : un entier,
tab_out : un tableau d'entiers,
taille_réele_out : un entier) -> vide
Lexique :
i : un entier
Algorithme :
Début
Si taille_pratique_in <= taille_réele_out
Alors i <- 0
Tant que i < taille_pratique_in
Faire tab_out[i] <- tab_in[i]
i <- i + 1
Fin
{Fonction 2
R : afficher les élements dun tableau dentiers sous la forme : {e1,e2,e3,...,en}
E : tab un tableau d'entiers, taille_pratique un entier
S : Vide}
afficher_tableau : une fonction(tab : un tableau d'entiers,
taille_pratique : un entier) -> vide
Lexique :
i : un entier
Algorithme :
Début
i <- 0
Tant que i < taille
Faire Ecrire(tab[i], ",") {On aura une virgule à la fin, mais l'enlever complexifierai inutilemment l'algorithme}
i <- i + 1
Fin
{Fonction 3
R : tester si deux tableaux sont identiques
E : tab1 un tableau d'entiers, taille_pratique_1 un entier, tab2 un tableau d'entiers, taille_pratique_2 un entier
S : vrai si les 2 tableau sont identiques}
sont_identiques : une fonction(tab1 : un tableau d'entiers,
tab2 : un tableau d'entiers,
taille_pratique_1 : un entier,
taille_pratique_2 : un entier) -> un booléen
Lexique :
i : un entier
Algorithme :
Début
Si taille_pratique_1 != taille_pratique_2
Alors Retourner(Faux)
i <- 0
Tant que i < taille_pratique_1
Faire Si tab1[i] != tab2[i]:
Alors Retourner(Faux)
Retourner(Vrai)
Fin
{Fonction 4
R : calculer la moyenne des élements dun tableau
E : tab un tableau d'entiers, taille_pratique un entier
S : un réel : la moyenne de tab}
moyenne_tableau : une fonction(tab : un tableau de réels,
taille_pratique : un entier) -> un réel
Lexique :
i : un entier
somme : un réel
Algorithme :
Début i <- 0
somme <- 0
Tant Que i < taille_pratique
Faire somme <- somme + tab[i]
Retourner(somme/taille_pratique)
Fin
{Fonction 5
R : remplacer les valeurs dun tableau par sa somme cumulée
E : tab le tableau d'entiers, taille_pratique un entier
E/S : tab le tableau de réels
S : vide}
somme_cumulee : une fonction(tab : un tableau d'entiers
taille_pratique : un entier) -> vide
Lexique :
i : un entier
j : un entier
somme : un réel
Algorithme :
Début i <- 0
Tant Que i < taille_pratique
Faire j <- 0
somme <- 0
Tant Que j <= i
Faire somme <- somme + tab[j]
tab[i] <- somme
i <- i + 1
Fin
Lexique :
Saisie_entiers : une fonction(tab: un tableau d'entiers, taille_réele : un entier) -> un entier
copy : une fonction(tab_in : un tableau d'entiers,taille_pratique_in : un entier,tab_out : un tableau d'entiers, taille_réele_out : un entier) -> vide
afficher_tableau : une fonction(tab : un tableau d'entiers, taille_pratique : un entier ) -> vide
sont_identiques : une fonction(tab1 : un tableau d'entiers, tab2 : un tableau d'entiers, taille_pratique_1 : un entier, taille_pratique_2 : un entier) -> un booléen
moyenne_tableau : une fonction(tab : un tableau d'entiers, taille_pratique : un entier) -> un réel
somme_cumulee : une fonction(tab : un tableau d'entiers, taille_pratique : un entier) -> vide
tab1 : un tableau de 1000 entiers
taille_réele_1 : la constante entière := 1000
taille_pratique_1 : un entier
tab1_copie : un tableau de 1000 entiers
taille_réele_copie_1 : la constante entière := 1000
tab2 : un tableau de 1000 entiers
taille_réele_2 : la constante entière := 1000
taille_pratique_2 : un entier
tab_1_et_2_identiques : un booléen
moyenne_tab1 : un réel
somme_cumulee_tab1_copie : un entier
Algorithme :
Début
taille_pratique_1 <- Saisie_entiers(tab1)
copy(tab1, taille_pratique_1, tab1_copie, taille_réele_copie_1)
afficher_tableau(tab1_copie, taille_pratique_copie_1)
taille_pratique_2 <- Saisie_entiers(tab2)
tab_1_et_2_identiques <- sont_identiques(tab1, tab2, taille_pratique_1, taille_pratique_2)
Ecrire(tab_1_et_2_identiques)
moyenne_tab1 <- moyenne_tableau(tab1, taille_pratique_1)
Ecrire(moyenne_tab1)
somme_cumulee_tab1_copie <- somme_cumulee(tab_copie, taille_pratique_copie_1)
Ecrire(somme_cumulee_tab1_copie)
Fin