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.
rgmarket
22.12.2022
Using System;
class Program { static void Main() { var random = new Random(DateTime.Now.Millisecond); int n = 5; int k; var c = new int[n, n]; var b = new int[n];
Console.WriteLine("C:"); for (var i = 0; i < n; i++) { for (var j = 0; j < n; j++) { c[i, j] = random.Next(0, 9); Console.Write(c[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); for(int j = 0; j < n; j++) { k = 0; for(int i = 0; i < n; i++) if (c[i, j]==0) k++; b[j] = k; } Console.WriteLine("B:"); for(int i = 0; i < n; i++) Console.Write(b[i] + " "); Console.WriteLine(); Console.ReadKey(); } }
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.