Petits rappels mathématiques :
0! =1
n! =1* 2* ...* n
n! = n* (n-1)!
n/ n! = 1/ (n-1)!
Ton problème se simplifie donc en 1/0! + 1/1! + 1/2! ... + 1/(n-1)!
Il te faut un accumulateur pour ta factorielle (initialisé à 0!=1)
program exo_facto;
var i,n,facto:integer; e:real;
begin
write('n = '); readln(n); // à ne pas oublier pour que ça marche
facto:=1; e:=1; // initialisation n=0
for i:=1 to (n-1) do
begin
facto:=facto*i; // facto = i!
e:=e+1/facto;
end;
writeln('e ~ ',e:0:15); // pour n grand e=exp(1)
writeln; write('Fin du programme. Appuyer sur Entree'); readln;
end.
La confiance n'exclut pas le contrôle