Aller au contenu

Algorithme


Marioon

Messages recommandés

Posté(e)

Bonjour , j'ai un problème avec cet exercice .

A la première question en faisant l'algorithme , je trouve 5 , je ne vois pas en quoi cette reponse est erronée .

Je ne donc pas faire la suivante ...

Un peu d'aide serait le bienvenu biggrin.png merci d'avance

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

/applications/core/interface/file/attachment.php?id=12444">math ex.pdf

math ex.pdf

  • E-Bahut
Posté(e)

Bonjour,

l'algo affiche 5 au lieu de 4 car lorsqu'il arrive avec i=4 à i²=16 , il augmente encore i de la valeur 1 donc il va afficher 5(= 4+1).

Pourquoi 5 est erroné ? Là, tu as tort avec 16

car l'énoncé dit que l'algo doit afficher le nb entier supérieur ou égal à racine de "n".

Donc avec 16 , il faut afficher 4.

Mais avec 17 , 18 , 19 ,20 ,21 ,22, 23 , 24 , il est bon et affiche 5.

On peut corriger ainsi ( fait avec Algobox):

VARIABLES

i EST_DU_TYPE NOMBRE

n EST_DU_TYPE NOMBRE

DEBUT_ALGORITHME

LIRE n

i PREND_LA_VALEUR 0

TANT_QUE (i*i<n) FAIRE

DEBUT_TANT_QUE

i PREND_LA_VALEUR i+1

FIN_TANT_QUE

AFFICHER i

FIN_ALGORITHME

Alors avec n=16 , on a bien l'affichage de 4 qui est la racine carrée de 16.

Et avec 17 , 18 , 19 ,20 ,21 ,22, 23 , 24 , il est bon et affiche 5.

Avec 25, il affiche 5. Etc.

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

×
×
  • Créer...
spam filtering
spam filtering