Const n=8; var a:array[1..n,1..n] of integer; i,j,k,s,s1,si,dmin,smin:integer; begin Randomize; writeln('Исходный массив:'); for i:=1 to n do begin for j:=1 to n do begin a[i,j]:=random(50); write(a[i,j]:4); end; writeln; end; write('k = '); readln(k); s:=0; for j:=1 to n do s:=s+a[k,j]; writeln('s = ',s); dmin:=999999; smin:=999999; for i:=1 to n do if i<>k then begin s1:=0; for j:=1 to n do s1:=s1+a[i,j]; writeln('s',i,' = ',s1); if abs(s1-s)<dmin then begin dmin:=abs(s1-s); smin:=s1; si:=i; end; end; writeln('Номер строки = ',si,', smin = ',smin); 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;
}
}
var
a:array[1..n,1..n] of integer;
i,j,k,s,s1,si,dmin,smin:integer;
begin
Randomize;
writeln('Исходный массив:');
for i:=1 to n do
begin
for j:=1 to n do
begin
a[i,j]:=random(50);
write(a[i,j]:4);
end;
writeln;
end;
write('k = '); readln(k);
s:=0;
for j:=1 to n do s:=s+a[k,j];
writeln('s = ',s);
dmin:=999999; smin:=999999;
for i:=1 to n do
if i<>k then
begin
s1:=0;
for j:=1 to n do s1:=s1+a[i,j];
writeln('s',i,' = ',s1);
if abs(s1-s)<dmin then begin dmin:=abs(s1-s); smin:=s1; si:=i; end;
end;
writeln('Номер строки = ',si,', smin = ',smin);
end.
Пример:
Исходный массив:
9 0 22 40 20 35 2 25
23 30 22 35 41 0 9 40
1 15 6 18 43 47 34 33
26 5 2 45 13 46 40 2
26 39 7 31 3 43 20 8
25 15 24 6 10 16 3 25
47 0 27 35 14 15 36 11
16 38 14 14 33 7 11 26
k = 5
s = 177
s1 = 153
s2 = 200
s3 = 197
s4 = 179
s6 = 124
s7 = 185
s8 = 159
Номер строки = 4, smin = 179