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;
if a [i] > 0 then begin
x := x * a [i];
Inc (c);
WriteLn ('Среднее геометрическое = ', Power (x, 1/c) :20 :15);
ReadLn;
end.
using System;
class Program
{
static void Main()
{
int x1 = 2, y1 = 1;
int x2 = 6, y2 = 5;
int x3 = 10, y3 = 1;
var a = Distance(x2, y2, x3, y3);
var b = Distance(x1, y1, x3, y3);
var c = Distance(x2, y2, x1, y1);
Console.WriteLine("S = {0}", Square(a, b, c));
Console.ReadKey();
}
//растояние между точками
static double Distance(int x1, int y1, int x2, int y2)
{
return Math.Sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
//формула герона
static double Square(double a, double b, double c)
{
var p = (a + b + c) / 2;
return Math.Sqrt(p * (p - a) * (p - b) * (p - c));
}
// теорема косинусов
static double Angle(double a, double b, double c)
{
return Math.Acos((b * b + c * c - a * a) / (2 * b * c));
}
static bool IsAcuteAngel(double alpha)
{
return alpha < Math.PI / 2;
}
}
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.