Programs Maple
Programs Maple
> Produit(5);
> ProduitTra(5);
{‐‐> enter ProduitTra, args = 5
Option remember
> ProduitRem:=proc(n)
local i,s;
option remember;
s:=1;
for i from 1 to n do
s:=s*i
od;
RETURN(s)
end:
> print("temps1",time());ProduitRem(1000):print("temps2",time());
> print("temps1",time());ProduitRem(1000):print("temps2",time());
>
> ProduitVL(5);i;s;
Variable globales
> ProduitGL:=proc(n)
# Je déclare les variables globales
global i,s;
s:=1;
for i from 1 to n do
s:=s*i
od;
RETURN(s)
end:
> ProduitGL(5);i;s;
> ProduitVLGL(5);
> suite5;
> suite4;
> ProduitRec(5);
> ProduitRecTr:=proc(n)
option trace;
if n=1 then
RETURN(1)
else
RETURN(n*ProduitRecTr(n-1))
fi
end:
> ProduitRecTr(5);
{‐‐> enter ProduitRecTr, args = 5
> Fibo(3);
{‐‐> enter Fibo, args = 3
> FiboRe(3);
{‐‐> enter FiboRe, args = 3
> FiboRe(4);
{‐‐> enter FiboRe, args = 4
> poids:=array(1..7,[1,2,3,4,5,6,7]):Npoids:=7:
for i from 1 to Npoids do
s:=NULL:
SacADos(12,i);print("12=",s)
od: