Ecrire l'algorithme qui calcule factorielle n (!n=1*2*3*...*n) par le biais d'une
boucle for. Le chiffre n est lu au clavier, et le résultat final est
affiché.

> restart;
n:=readstat(`entrez le nombre dont vous souhaitez le factoriel `):
s:=1:
for i from 2 to n do
s:=s*i:
od:
print(cat(`!`,n,`=`,s));

entrez le nombre dont vous souhaitez le factoriel 6;

[Maple Math]

Ecrire un programme Maple qui calcule la somme des n premiers entiers
pairs strictement positifs, la valeur de n étant saisie au clavier et
le résultat affiché.

> restart;
n:=readstat(`Entrez un nombre `);
s:=0;
for i from 2 to 2*n by 2 do
s:=s+i;
od;
print(s);

Entrez un nombre 3;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Autre solution:

> restart;
n:=readstat(`Entrez un nombre `);
s:=0;i:=1;
while i<=n do
s:=s+2*i;
i:=i+1;
od;
print(s);

Entrez un nombre 3;

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Ecrire un programe capable de déterminer jusqu'à quel entier il faut
aller pour que la somme des premiers entiers positifs dépasse 1000.

> restart;
i:=0;
s:=0;
while s<1000 do
i:=i+1;
s:=s+i;
od;
print(i);

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

Ecrire un programme Maple qui détermine la somme Sn=x1+x2+...+xn
de n nombres saisis successivement au clavier. La saisie des nombres
sera arrêtée en tapant le mot `fin`.

> restart;
s:=0;
i:=readstat(`entrez un nombre ou fin `);
while i<> fin do
s:=s+i;
i:=readstat(`entrez un nombre ou fin `);
od;
print(s);

[Maple Math]

entrez un nombre ou fin 1;

[Maple Math]

[Maple Math]

entrez un nombre ou fin 2;

[Maple Math]

[Maple Math]

entrez un nombre ou fin 3;

[Maple Math]

[Maple Math]

entrez un nombre ou fin 45;

[Maple Math]

[Maple Math]

entrez un nombre ou fin fin;

[Maple Math]

[Maple Math]


Ecrire un programme Maple, qui affiche le motif suivant:

o

oo
ooo
oooo
ooooo
oooo

ooo

oo

o

> #solution 1: faire la pyramide ascendante puis la descendante

> restart;
for i from 1 to 5 do
ligne:=``:
for j from 1 to i do
ligne:=cat(ligne,`o`):
od:
print(ligne):
od:
for i from 4 to 1 by -1 do
ligne:=``:
for j from 1 to i do
ligne:=cat(ligne,`o`):
od:
print(ligne):
od:

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

> #solution 2

> restart:
i:=1:count:=1:
while (i>0) do
ligne:=``:
for j from 1 to i do
ligne:=cat(ligne,`o`):
od:
print(ligne):
count:=count+1:
i:=`if`(count>5,i-1,i+1):
od:

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]

[Maple Math]


Soit le jeu dont les règles sont les suivantes: L'ordinateur tire un
nombre au hasard (Faire myrand:=rand(i..n) en Maple, puis utiliser la fonction myrand() qui renvoie un
nombre au hasard entre i et n.) entre 0 et 1000. Le joueur a 10 essais pour trouver
ce nombre, sachant qu'en cas d'erreur, le programme lui répond ``trop
grand'' ou ``trop petit''. Si le joueur entre le bon nombre, il gagne, et si à la dixième tentative le joueur
n'a toujours pas proposé le bon nombre, il a perdu.

>

> restart;

> tmp:=rand(1..1000):

> r:=tmp():
res:=false:
for i from 1 to 10 do
t:=readstat("proposez un nombre! "):
if t=r then
res:=true:
break:
fi:
`if`(t<r,print(`trop petit!`),print(`trop grand`)):
od:

print(`if`(res,`bravo`,`perdu`)):

proposez un nombre! 500;

[Maple Math]

proposez un nombre! 250;

[Maple Math]

proposez un nombre! 125;

[Maple Math]

proposez un nombre! 81;

[Maple Math]

proposez un nombre! 83;

[Maple Math]

proposez un nombre! 82;

[Maple Math]

>