1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| Program Fonction8;
uses math,crt;
var i,n : integer;
x,s,t : real;
choix : char;
procedure exp(x,n,s);
begin
t:=1;
s:=t;
For i:=1 to n do begin
t := t * x / i;
s:=s+t;
end;
writeln('exp(x) =',s:3:2);
writeln('exp(x) theor =',exp(x):3:2);
end;
procedure ln(x,n,s);
begin
if (x>0) and (x<1) then begin
t:=x;
s:=t;
For i:=2 to n do
begin
t := -1 * t * x * (i-1) / i;
s:=s+t;
end;
writeln('ln(x) =',s:3:2);
writeln('ln(x) theor =',ln(x+1):3:2);
end
else writeln('Ln(x+1) ne fonctionne que avec un x dans [0,1[ !!!');
end;
Procedure cos(x,n,s);
begin
t:=1;
s:=t;
For i:=1 to n do begin
t := -1 *t * x * x / (2*i*((2*i)-1));
s:=s+t;
end;
writeln('cos(x) =',s:3:2);
writeln('cos(x) theor =',cos(x):3:2);
end;
procedure sin(x,n,s);
begin
t:=1;
s:=t;
For i:=1 to n do begin
t := -1 *t * x * x / (2*i*((2*i)-1));
s:=s+t;
end;
writeln('cos(x) =',s:3:2);
writeln('cos(x) theor =',cos(x):3:2);
END;
begin
modx:=0;
modn:=0;
choix := 'i';
while (choix <> 'Q') do begin
Repeat
readln;
clrscr;
writeln('Evaluation ');
writeln('+++++++++++');
writeln('E exp(x) ');
writeln('L ln(x+1)');
writeln('C cos(x) ');
writeln('S sin(x) ');
writeln();
writeln('T toutes ');
writeln('-----------');
writeln('X changer X (',x:3:2,')');
writeln('N changer nbre d''iteration (',n,')');
writeln('-----------');
writeln('Q Quitter');
writeln();
writeln('Votre choix ? ... ');
readln(choix);
Until upcase(choix) in ['E','L','C','S','X','N','Q'];
case upcase(choix) of
'E' : exp(x,n,s)
'L' : ln(x,n,s)
'C' : cos(x,n,s)
'S' : sin(x,n,s)
'x' : BEGIN
writeln('Entrez une nouvelle valeur pour X entier');
readln(x);
END;
'n' : BEGIN
writeln('Entrez une nouvelle valeur pour n entier');
readln(n);
END;
'Q' : BEGIN
repeat
writeln('Voulez vous vraiment quitter ? [O/N]');
readln(choix);
until upcase(choix) in ['O','N'];
if (upcase(choix)='N') then choix:='i'
else begin writeln('Au revoir'); choix := 'Q'; readln(); end;
END;
end;
end;
end. |
Partager