program Project2; {$APPTYPE CONSOLE} uses SysUtils,windows;
var a,b:array of real; i:byte; cs,sk,da,db:real; n:integer; begin SetConsoleOutputCP(1251); randomize; writeln('Введите n'); readln(n); Setlength(a,n); Setlength(b,n); writeln('Вектор À'); for i:=0 to high(a) do begin a[i]:=-5+10*random; write(a[i]:5:1); end; writeln; writeln('Вектор B'); for i:=0 to High(b) do begin b[i]:=-5+10*random; write(b[i]:5:1); end; writeln; {Скалярные произведения и длинны векторов} sk:=0; da:=0; db:=0; for i:=0 to n-1 do begin sk:=sk+a[i]*b[i]; da:=da+sqr(a[i]); db:=db+sqr(b[i]); end; {Косинус} cs:=sk/sqrt(da)/sqrt(db); write('Cos(aльфа)=',cs:0:3); readln; end.
Answers & Comments
Verified answer
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils,windows;
var a,b:array of real;
i:byte;
cs,sk,da,db:real; n:integer;
begin
SetConsoleOutputCP(1251);
randomize;
writeln('Введите n');
readln(n);
Setlength(a,n);
Setlength(b,n);
writeln('Вектор À');
for i:=0 to high(a) do
begin
a[i]:=-5+10*random;
write(a[i]:5:1);
end;
writeln;
writeln('Вектор B');
for i:=0 to High(b) do
begin
b[i]:=-5+10*random;
write(b[i]:5:1);
end;
writeln;
{Скалярные произведения и длинны векторов}
sk:=0;
da:=0;
db:=0;
for i:=0 to n-1 do
begin
sk:=sk+a[i]*b[i];
da:=da+sqr(a[i]);
db:=db+sqr(b[i]);
end;
{Косинус}
cs:=sk/sqrt(da)/sqrt(db);
write('Cos(aльфа)=',cs:0:3);
readln;
end.