Перевести программу из Паскаля в С++

Дмитрий Агеев

{$G+,N+} {Подрубаем 286 и сопроцессор, можно и без них}

Uses CRT;
Const
AA : Real = 0; {Нижний предел}
BB : Real = 5; {Верхний предел}
NN : Word = 8; {Кол-во итераций}

Function F(X:Real):Real; {Подынтегральная функция}
Begin
F := 1/sqrt(x+4);
End;

Function GaussMethod(A,B: Real;N:Word):Real;
{Интегрирование по квадратурной формуле Гаусса, N - от 1 до 8
чем больше N, тем точнее вычисления
ВНИМАНИЕ! Проверка на допустимые значения N не осуществляется!!!
}
Const
Xi : Array [1..8,1..8] of Real = (
(0.5 ,0 ,0 ,0 ,0 ,0 ,0,0),
(-0.577350,0.577350 ,0 ,0 ,0 ,0 ,0,0),
(-0.774597,0 ,0.774597 ,0 ,0 ,0 ,0,0),
(-0.861136,-0.339981,0.339981 ,0.861136 ,0 ,0 ,0,0),
(-0.906180,-0.538470,0 ,0.538470 ,0.906180,0 ,0,0),
(-0.932470,-0.661210,-0.238620,0.238620 ,0.661210,0.932470,0,0),
(-0.949108,-0.741531,-0.405845,0 ,0.405845,0.741531,0.949108,0),
(-0.960290,-0.796666,-0.525532,-0.183434,0.183434,0.525532,0.796666,0.960290)
);

Ci : Array [1..8,1..8] of Real = (
(2,0,0,0,0,0,0,0),
(1,1,0,0,0,0,0,0),
(0.555555,0.888889,0.555555,0,0,0,0,0),
(0.347855,0.652145,0.652145,0.347855,0,0,0,0),
(0.236927,0.478629,0.568889,0.478629,0.236927,0,0,0),
(0.171324,0.360761,0.467914,0.467914,0.360761,0.171324,0,0),
(0.129485,0.279705,0.381830,0.417960,0.381830,0.279705,0.129485,0),
(0.101228,0.222381,0.313707,0.362684,0.362684,0.313707,0.222381,0.101228)
);
Var
Ing : real;
I : Byte;
Begin
Ing := 0;
For I := 1 to N do
Ing := Ing + F( (a+b)/2+((b-a)/2)Xi[n,I] )*Ci[n,I];
GaussMethod := Ing
((b-a)/2);
End;

Begin
WriteLn('Квадратурная формула Гаусса : ',GaussMethod(AA,BB,NN):0:3);
ReadLn;
End.

2 чел.