fonction aire_perimetre_carre(E cote:reel, S aire:reel):reel { variable perimetre : reel aire <-- cote * cote perimetre <-- 4 * cote retourne perimetre } fonction aire_perimetre_carre2(E cote:reel, S perimetre:reel):reel { variable aire : reel aire <-- cote * cote perimetre <-- 4 * cote retourne aire } fonction aire_carre(E cote:reel):reel { variable aire : reel aire <-- cote * cote retourne aire } fonction perimetre_carre(E cote:reel):reel { variable perimetre : reel perimetre <-- 4 * cote retourne perimetre } Algorithme Appel_aire_perimetre { variable c, a, p : reel Afficher("Saisir le coté du carre : ") Saisir(c) Afficher("Le périmètre est : ", aire_perimetre_carre(c, a), "et l'aire est", a) // Attention ce qui suit en commentaire ne fonctionnerait pas. // Afficher("L'aire est : ", a, "et le périmètre est ", aire_perimetre_carre(c, a)) Afficher("L'aire et le périmètre du carré de coté ", c, " sont ", aire_carre(c), " et ", perimetre_carre(c), ".\n") } fonction est_impair(E x:entier): booleen { variable impair : booleen Si (x mod 2 = 0) alors { impair <-- FAUX } sinon { impair <-- VRAI } retourne impair } Algorithme Appel_est_impair { variable n : entier Afficher("Saisir un nombre : ") Saisir(n) Si (est_impair(n)) alors Afficher("Le nombre ", n, " est impair.\n") sinon Afficher("Le nombre ", n, " est pair.\n") } fonction ajout_dix(E x:entier):entier { retourne x + 10 } Algorithme Appel_ajout_dix { variable n : entier Afficher("Saisir un nombre : ") Saisir(n) Afficher("Le nombre initial est", n, "et il vaut maintenant ", ajout_dix(n), ".\n") } // LA SUITE MARCHE MAIS C'EST MOCHE !!!! Le type de retour ne sert à rien fonction permutation(E/S A: entier, E/S B: entier): entier { variable Z : entier Z <-- A A <-- B B <-- Z retourne 0 } Algorithme Appel_permutation { variable n, m, a : entier Afficher("Saisir deux nombres : ") Saisir(n, m) a <-- permutation(n,m) // la variable a ne sert à RIEN. // C'EST UNE MAUVAISE SOLUTION Afficher("Le premier nombre est maintenant ", n, " et le second est ", m,".\n") } // ON NE PEUT PAS VRAIMENT FAIRE UNE BELLE FONCTION // SAUF A RAJOUTER UN TYPE DE RETOUR QUI NE SERT A RIEN. procedure tri_croissant(E/S A : entier, E/S B : entier, E/S C : entier) { Si (A > B) alors { permutation(A,B) } Si (B > C) alors { permutation(B,C) } Si (A > B) alors { permutation(A,B) } } Algorithme Appel_tri { variable a,b,c : entier Afficher("Saisir trois entiers : ") Saisir(a,b,c) tri_croissant(a,b,c) Afficher("Le résultat du tri est ",a,"<",b,"<",c,".\n") } fonction reste_division_euclidienne(E A : entier, E B : entier): entier { retourne A mod B } fonction quotient_division_euclidienne(E A : entier, E B : entier): entier { retourne A div B } Algorithme Appel_division { variable a,b,q,r : entier Afficher("Saisir deux entiers : ") Saisir(a,b) r <-- reste_division_euclidienne(a,b) q <-- quotient_division_euclidienne(a,b) Afficher("Le quotient de la division euclidienne de ",a, " par ", b, " est ",q," et le reste est ",r,".\n") } fonction nb_jours_du_mois(E mois : entier, E annee : entier) : entier { variable nbjours : entier Selon(mois) { 1, 3, 5, 7, 8, 10, 12 : nbjours <-- 31 4, 6, 9, 11 : nbjours <-- 30 2 : Si (annee mod 4 = 0) alors nbjours <-- 29 sinon nbjours <-- 28 } retourne nbjours } Algorithme Appel_nbjours { variable mois, annee : entier Afficher("Saisir un mois et une année : ") Saisir(mois, annee) Afficher("Il y a ", nb_jours_du_mois(mois, annee), " jours dans le mois ", mois,"/",annee,".\n") }