program Geom;
program Test_nn;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Math;
var
a: array of Extended;
n, i, c: Integer;
x: Extended;
begin
Write ('Размерность массива = ');
ReadLn (n);
SetLength (a, n);
Randomize;
for i := Low (a) to High (a) do begin
a [i] := (Random (2001) - 1000) / 1000;
Write (a [i] :7 :3);
end;
x := 1;
c := 1;
WriteLn;
for i := Low (a) to High (a) do begin
if a [i] > 0 then begin
Write (a [i] :7 :3);
x := x * a [i];
Inc (c);
end;
end;
WriteLn;
WriteLn ('Среднее геометрическое = ', Power (x, 1/c) :20 :15);
ReadLn;
end.
#include <iostream>
double multiply(double num1, double num2) {
if (num2 > 0) return num1 + multiply(num1, num2 - 1);
else if (num2 < 0) return -num1 + multiply(num1, num2 + 1);
return 0;
}
signed main() {
//2.2 * 2
std::cout << multiply(2.2, 2) << std::endl;
//4 * 2
std::cout << multiply(4, 2) << std::endl;
//-8 * 2
std::cout << multiply(-8, 2) << std::endl;
//0*1
std::cout << multiply(0, 1) << std::endl;
return 0;
}