1. début – fin 2. lecture – écriture 3. calculs – affectation de variables

Unalgorithmeestunedescriptionstructuréedelalistedesactionseffectuéesparunprogramme.
Ilpeutêtrereprésentégraphiquement,c’estalorsunorganigramme(oualgorigramme),ouécritsousuneformelittérale,appelée
langagealgorithmique.Onl’appellera«l’algorithme»poursimplifier.Eneffet,danslesexercices,unalgorithmeapparaîtraleplus
courammentsousformed’unelisted’instructions,souventdanslelangageAlgoBox.
L’organigramme,quin’estpasexigibleici,permetcependantdanscertainscasdemieuxcomprendrecertainesprocéduresà
effectuer,carl’aspectlinéairedel’algorithmeclassiquepeutparfoismanquerdeclarté.
1.DÉBUTFIN
Extrémitésdel’algorithme,symboliséespardes«stades»(rectanglesencadrésdedeuxdemicercles).
DÉBUT:Doitêtresuivideladéfinitiondesvariablesutiliséesdansl’algorithme.
FIN:Doitthéoriquementêtrelepassageobligéàlafindelaprocédure.Sicen’estpaslecas,l’algorithmerisquede«tourner»
indéfiniment.
2.LECTUREÉCRITURE
Transfertsd’informationsentrel’utilisateuretlamachine.
LECTURE:saisie(transfertdel’utilisateurverslamachine),àl’aideduclavier[instructionsymboliséeparunparallélogramme]).
ÉCRITURE:affichage(transfertdelamachineversl’utilisateur),àl’aidedel’écran[mêmesymbolisme]).
3.CALCULSAFFECTATIONDEVARIABLES
CALCULS:Traitementinterneàlamachine[symbolisésparunrectangle].
AFFECTATIONDEVARIABLES:Stockagedevaleursnumériques(ouautres…),repéréesparleurnom[symboliséesparunelettreou
mêmeparfoisunmot].
Exemple3.1:Calculdupérimètreetdelasuperficied’unrectangleconnaissantsesdimensions.
Organigramme:EnlangageAlgoBox:
1 VARIABLES
2  aEST_DU_TYPENOMBRE
3  bEST_DU_TYPENOMBRE
4  PEST_DU_TYPENOMBRE
5  SEST_DU_TYPENOMBRE
6 DEBUT_ALGORITHME
7  LIREa
8  LIREb
9  PPREND_LA_VALEUR2*(a+b)
10  SPREND_LA_VALEURa*b
11  AFFICHER"Périmètre:"
12  AFFICHERP
13  AFFICHER"Superficie:"
14  AFFICHERS
15 FIN_ALGORITHME
Exercice3.2:Construireunorganigrammeetunalgorithme
permettantdecalculerlasuperficied’undisqueconnaissant
sonpérimètre.
Exercice3.3:Dansl’algorithmecicontre,montrerquel’on
pourraitexprimerydirectementenfonctiondexavecune
instructionnecomportantqu’uneseuleopération.
Exercice3.4:Construirel’organigrammeetl’algorithmedu
problèmesuivant:CalculerleprixHTd’unobjetconnaissant
sonprixTTC(letauxdeTVAétantvariableetdonnépar
l’utilisateur).
1 VARIABLES
2  aEST_DU_TYPENOMBRE
3  bEST_DU_TYPENOMBRE
4  cEST_DU_TYPENOMBRE
5  dEST_DU_TYPENOMBRE
6  xEST_DU_TYPENOMBRE
7  yEST_DU_TYPENOMBRE
8 DEBUT_ALGORITHME
9  LIREx
10  aPREND_LA_VALEURx+2
11  bPREND_LA_VALEURa*a
12  cPREND_LA_VALEURx2
13  dPREND_LA_VALEURc*c
14  yPREND_LA_VALEUR(bd)/4
15 AFFICHERy
16 FIN_ALGORITHME
Exercice3.5:Explicitercequefontlesdeuxalgorithmescidessouset
expliquerpourquoiilsnedonnentpas(engénéral)lemême
résultat.
1 VARIABLES
2  aEST_DU_TYPENOMBRE
3  bEST_DU_TYPENOMBRE
4  cEST_DU_TYPENOMBRE
5 DEBUT_ALGORITHME
6  LIREa
7  LIREb
8  LIREc
9  cPREND_LA_VALEURa+b
10  aPREND_LA_VALEURb+c
11  bPREND_LA_VALEURc+a
12  AFFICHER"a="
13  AFFICHERa
14  AFFICHER"b="
15  AFFICHERb
16  AFFICHER"c="
17  AFFICHERc
18 FIN_ALGORITHME
1 VARIABLES
2  aEST_DU_TYPENOMBRE
3  bEST_DU_TYPENOMBRE
4  cEST_DU_TYPENOMBRE
5 DEBUT_ALGORITHME
6  LIREa
7  LIREb
8  LIREc
9  aPREND_LA_VALEURb+c
10  bPREND_LA_VALEURc+a
11  cPREND_LA_VALEURa+b
12  AFFICHER"a="
13  AFFICHERa
14  AFFICHER"b="
15  AFFICHERb
16  AFFICHER"c="
17  AFFICHERc
18 FIN_ALGORITHME
Exercice3.6:Simplifierl’algorithmecidessousen
n’utilisantquelavariablex.
1 VARIABLES
2  xEST_DU_TYPENOMBRE
3  yEST_DU_TYPENOMBRE
4  zEST_DU_TYPENOMBRE
5 DEBUT_ALGORITHME
6  LIREx
7  yPREND_LA_VALEUR2*x+1
8  zPREND_LA_VALEURy*y1
9  xPREND_LA_VALEURz/4
10  AFFICHERx
11 FIN_ALGORITHME
Exercice3.7:Écrireunalgorithmepermettantd’échanger
lesvaleursdedeuxvariables.
Exercice3.8:Unalgorithmecontientdanscetordreles
instructionssuivantes:
«aprendlavaleur5»,«bprendlavaleur2»,
«aprendlavaleurb»et«bprendlavaleura».
Déterminerlesvaleursfinalesdeaetdebetfaire
uneremarqueconcernantl’unedesinstructions.
Exercice3.9:Écrirel’algorithmesuivantetcommenterlerésultat:choisirunentier,calculerlecarrédel’entiersuivant,puisle
carrédel’entierprécédent,puisladifférence(positive)decesdeuxcarrés,puisenfinlequotientdecedernierrésultatpar
l’entierdedépart.
Exercice3.10:Écrirel’algorithmepermettantdecalculerlamoyenne(sanscoefficients)detroisnotesdecontrôle,donnéespar
l’utilisateur.
Exercice3.11:Mêmeexercicequeprécédemmentavecunemoyenneaveccoefficients,donnésaussiparl’utilisateur.
Exercice3.12:Écrirel’algorithmepermettantdecalculerlepourcentagedevariationentreunpremiernombreetundeuxième,
donnésdansl’ordreparl’utilisateur.
Exercice3.13:Écrirel’algorithmepermettantdecalculerletermederangnd’unesuitearithmétique,l’entiern,lepremierterme
etlaraisonétantdonnésparl’utilisateur.
Mêmequestionavecunesuitegéométrique.
4.TEST
TEST«SI…ALORS…[SINON]»:permetunchoixayantdeuxréponsespossibles(VRAIouFAUX),avecdesinstructionsàréalisersila
réponseestVRAI,etéventuellementsilaréponseestFAUX,parl’intermédiaired’un«SINON»[symboliséeparunlosangele
branchementpourFAUXestparfoisrepéréparunrondnoir].
Exemple4.1:Calculdelaracinecarréed’unréelpositif,etsansréactionlorsqu’ilestnégatif.
1 VARIABLES
2  aEST_DU_TYPENOMBRE
3  bEST_DU_TYPENOMBRE
4 DEBUT_ALGORITHME
5  LIREa
6  SI(a>=0)ALORS
7  DEBUT_SI
8bPREND_LA_VALEURsqrt(a)
9AFFICHER"Laracinecarréedeaest:"
10AFFICHERb
11  FIN_SI
12FIN_ALGORITHME
Exemple4.2:Calculdelaracinecarréed’unréelpositif,etaffichaged’unmessaged’erreurlorsqu’ilestgatif.
1 VARIABLES
2  aEST_DU_TYPENOMBRE
3  bEST_DU_TYPENOMBRE
4 DEBUT_ALGORITHME
5  LIREa
6  SI(a>=0)ALORS
7  DEBUT_SI
8bPREND_LA_VALEURsqrt(a)
9AFFICHER"Laracinecarréedeaest:"
10AFFICHERb
11  FIN_SI
12  SINON
13DEBUTSINON
14AFFICHER«Pasderacinecarrée!»
15FINSINON
16 FIN_ALGORITHME
Remarque4.3:«sqrt(a)»renvoieenlangageAlgoBoxlaracinecarrée(positive)dea(lorsqueaestpositif).
Exercice4.4:Voicil’organigrammeetl’algorithmeducalculdelavaleurabsolued’unréel.
Refairel’unetl’autresansutiliserl’instruction«SINON».
1VARIABLES
2  aEST_DU_TYPENOMBRE
3  bEST_DU_TYPENOMBRE
4 DEBUT_ALGORITHME
5  LIREa
6  SI(a>0)ALORS
7  DEBUT_SI
8  bPREND_LA_VALEURa
9  FIN_SI
10  SINON
11  DEBUT_SINON
12  bPREND_LA_VALEUR‐a
13  FIN_SINON
14  AFFICHER"Lavaleurabsoluede"
15  AFFICHERa
16  AFFICHER"est:"
17  AFFICHERb
18FIN_ALGORITHME
Exercice4.5:Construireunorganigrammeetl’algorithmecorrespondant,indiquantleplusgranddedeuxréelsdonnéspar
l’utilisateur.Prévoirunmessagesilesdeuxnombressontégaux.
Exercice4.6:Écrireunalgorithmesaisissantcinqréelsdonnésparl’utilisateuretindiquant,aufuretàmesure,leplusgranddes
réelssaisis.
5.TESTAVECCONNECTEURS
Remarque5.1:SiAetBsontdeuxaffirmationspouvantêtrevraiesoubienfausses,alorsl’affirmation(AETB)estvraiesiet
seulementsilesdeuxaffirmationssontvraiessimultanément,et(AOUB)estvraiesietseulementsiaumoinsl’unedesdeux
affirmationsestvraie.
Exemple5.2:Déterminationsiunnombreappartientàl’intervalle[1;5].
1 VARIABLES
2  xEST_DU_TYPENOMBRE
3 DEBUT_ALGORITHME
4  LIREx
5  SI((x>=1)ET(x<=5))ALORS
6  DEBUT_SI
7AFFICHER"Lenombreestdansl’intervalle"
8  FIN_SI
9  SINON
10DEBUT_SINON
11AFFICHER"Lenombren’estpasdansl’intervalle"
12FIN_SINON
13 FIN_ALGORITHME
Exemple5.3:Déterminationdusigneduproduitdedeuxnombresnonnulssansfairelecalculduproduit.
1 VARIABLES
2  aEST_DU_TYPENOMBRE
3  bEST_DU_TYPENOMBRE
4 DEBUT_ALGORITHME
5  LIREa
6  LIREb
7  SI((a>0ETb>0)OU(a<0ETb<0))ALORS
8  DEBUT_SI
9AFFICHER"Leproduitestpositif"
10  FIN_SI
11  SINON
12DEBUT_SINON
13AFFICHER"Leproduitestnégatif"
14FIN_SINON
15 FIN_ALGORITHME
Exercice5.4:Écrireunalgorithmepermettantdevérifiersiunréelasoncarrésupérieurouégalà1,sanscalculereffectivementle
carré.
Exercice5.5:Écrireunalgorithmesaisissanttroisréelsdonnésparl’utilisateuretindiquants’ilsontétésaisisdansl’ordrecroissant,
décroissantoudansledésordre.
Exercice5.6:Uneannéeestbissextilelorsqu’elleestdivisiblepar4,sansêtredivisiblepar100,saufsielleestdivisiblepar400.
Écrireunalgorithmeindiquantsiuneannée,saisieparl’utilisateur,estbissextileounon.
6.TESTSIMBRIQUÉS
Exemple6.1:Affichagedesrésultatsàunexamenselonlamoyenneobtenueparlecandidat.
Remarque6.2:L’organigrammeindiqueaprèschaqueaffichageuntransfert«ALLERÀ»vers«FIN».Cependant,dansun
algorithme,ilestclassiqued’imbriquerlestestspourévitercestransferts.
1 VARIABLES
2  nEST_DU_TYPENOMBRE
3 DEBUT_ALGORITHME
4  LIREn
5  SI(n>=12)ALORS
6  DEBUT_SI
7  AFFICHER"Reçuavecmention"
8  FIN_SI
9  SINON
10DEBUT_SINON
11SI(n>=10)ALORS
12DEBUT_SI
13AFFICHER"Reçu"
14FIN_SI
15SINON
16DEBUT_SINON
17SI(n>=8)ALORS
18DEBUT_SI
19AFFICHER"Oralderattrapage"
20FIN_SI
21SINON
22DEBUT_SINON
23AFFICHER"Refusé"
24FIN_SINON
25FIN_SINON
26FIN_SINON
27 FIN_ALGORITHME
Exemple6.3:Résolutiondel’équationax+b=0,dontl’inconnueestx.
1 VARIABLES
2 aEST_DU_TYPENOMBRE
3 bEST_DU_TYPENOMBRE
4 uEST_DU_TYPENOMBRE
5 DEBUT_ALGORITHME
6 SI(a==0)ALORS
7   DEBUT_SI
8 SI(b==0)ALORS
9 DEBUT_SI
10 AFFICHER"Toutxestsolution"
11 FIN_SI
12 SINON
13 DEBUT_SINON
14 AFFICHER"Pasdexsolution"
15 FIN_SINON
16   FIN_SI
17 SINON
18   DEBUT_SINON
19 uPREND_LA_VALEUR‐b/a
20 AFFICHER"x="
21 AFFICHERu
22 FIN_SINON
23 FIN_ALGORITHME
Exercice6.4:Écrireunalgorithmepermettantlarésolution,dansl’ensembledesréels,del’équationduseconddegré
ax²+bx+c=0(avecanonnul).
Exercice6.5:Écriredeuxalgorithmes(l’unavecconversionenminutesetl’autrenon)permettantdefairelecalculsuivant:
l’utilisateurindiqueunhoraire(deuxvariables:l’uneindiquantlesheures,l’autrelesminutes),etl’algorithmeindique
l’horaire15minutesplustard(mêmeconfiguration).Nepasoublierd’étudierlechangementdejouréventuel.
1 / 9 100%

1. début – fin 2. lecture – écriture 3. calculs – affectation de variables

La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !