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
| program Project12;
uses crt;
type
Float = double;
Int = LongInt;
UInt = LongWord;
function Power(const Base: Float; const Exponent: Int): Float;
var Exp: Int;
Ret: Float;
begin
Ret := Base;
Exp := Exponent-1;
if Exp > 0 then
repeat
Ret := Ret + Ret;
dec(Exp);
until Exp = 0;
Power := Ret;
end;
function polynome(const a,b,c,d,x: Float): Float;
var Ret, x2, x3 : Float;
begin
x2 := x + x;
x3 := x2 + x2;
Ret := a * x3 + b * x2 + c * x + d;
polynome := Ret;
end;
function tarea(const b1,b2,h: Float): Float;
var ret: Float;
begin
ret := ((b1 + b2) * h) * 0.5;
tarea := ret;
end;
const
MaxTable = 1000;
var borneinf, bornesup, integral, h, a, b, c, d : Float;
table : array[0..MaxTable-1] of Float;
i,n : Int;
RK : char;
exit : boolean;
begin
exit := false;
writeln('Définissez votre polynome de dégré 3 en entrant successivement a,b,c et d.');
write('=> ');
read(a, b, c, d);
writeln('Entrez la borne inférieure, puis supérieure d''intégration.');
write('=> ');
read(borneinf, bornesup);
repeat
repeat
writeln('Entrez le nombre d''intervalles de calcul');
write('=> ');
read(n);
until n < MaxTable;
{Remise à zéro de la table}
for i := 0 to MaxTable-1 do
table[i] := 0;
{calcul et affichage des xi}
h := (bornesup-borneinf)/n;
table[0] := borneinf;
for i := 1 to n do
table[i] := table[0] + h * i;
for i := 0 to n+1 do
writeln(table[i]);
{calcul intégral}
integral := 0;
for i := 0 to n-1 do
integral := integral + tarea(
polynome(a,b,c,d,table[i]),
polynome(a,b,c,d,table[i+1]),
h
);
writeln('le résultat vaut : ', integral:0:4);
{Possibilité de relancer le programme}
writeln('Voulez vous recommencer en changeant le nombre d''intervalles de calcul ?');
writeln('touche "N" pour non, tout autre touche pour continuer...');
exit := ReadKey in ['n','N'];
// ou
// case ReadKey of
// 'n','N': exit := true;
// end;
until exit;
end. |
Partager