Помогите решить задачу (Заплачу)
Дана матрица S1 (4;6), ввести значение по столбцам. Определить и вывести номер столбца, сумма элементов которого имеет максимальное значение. Кто поможет кину на телефон 200 рублей, напишите телефон. 4 - количество строк, 6 - количество столбцов написать программу с процедурами
Код:
program MaxColumn; {maximum sum of column in array}
uses Crt; {module for clrscr and readkey}
type
mas = array[1..4, 1..6] of real;
var
S1: mas;
{input array from user}
procedure input(var S1: mas);
var
i, j: integer;
begin
for j := 1 to 6 do begin
WriteLn('Input ', j, ' column:');
for i := 1 to 4 do begin
ReadLn(S1[i,j]);
end;
end;
end;
{find needed column}
function maxcol(S1: mas) : integer;
var
i, j: integer;
sum, max: real;
begin
for j := 1 to 6 do begin
sum := 0;
for i := 1 to 4 do begin
sum := sum + S1[i,j];
end;
if j = 1 then begin
max := sum;
maxcol := j;
end
else begin
if sum > max then begin
max := sum;
maxcol := j;
end;
end;
end;
end;
begin
ClrScr; {clearing screen}
input(S1);
WriteLn('Column with maximum sum is ', maxcol(S1));
Write('Press any key to continue . . .');
ReadKey; {wait for the key pressing}
end.
uses Crt; {module for clrscr and readkey}
type
mas = array[1..4, 1..6] of real;
var
S1: mas;
{input array from user}
procedure input(var S1: mas);
var
i, j: integer;
begin
for j := 1 to 6 do begin
WriteLn('Input ', j, ' column:');
for i := 1 to 4 do begin
ReadLn(S1[i,j]);
end;
end;
end;
{find needed column}
function maxcol(S1: mas) : integer;
var
i, j: integer;
sum, max: real;
begin
for j := 1 to 6 do begin
sum := 0;
for i := 1 to 4 do begin
sum := sum + S1[i,j];
end;
if j = 1 then begin
max := sum;
maxcol := j;
end
else begin
if sum > max then begin
max := sum;
maxcol := j;
end;
end;
end;
end;
begin
ClrScr; {clearing screen}
input(S1);
WriteLn('Column with maximum sum is ', maxcol(S1));
Write('Press any key to continue . . .');
ReadKey; {wait for the key pressing}
end.
4 - это количество строк, а 6 - количество столбцов? Так?
Код:
program MaxColumn; {maximum sum of column in array}
uses Crt; {module for clrscr and readkey}
type
mas = array[1..4, 1..6] of real;
var
i, j, argmax: integer;
sum, max: real;
S1: mas;
begin
ClrScr; {clearing screen}
for j := 1 to 6 do begin
WriteLn('Input ', j, ' column:');
for i := 1 to 4 do begin
ReadLn(S1[i,j]);
end;
end;
for j := 1 to 6 do begin
sum := 0;
for i := 1 to 4 do begin
sum := sum + S1[i,j];
end;
if j = 1 then begin
max := sum;
argmax := j;
end
else begin
if sum > max then begin
max := sum;
argmax := j;
end;
end;
end;
WriteLn('Column with maximum sum is ', argmax);
Write('Press any key to continue . . .');
ReadKey; {wait for the key pressing}
end.
uses Crt; {module for clrscr and readkey}
type
mas = array[1..4, 1..6] of real;
var
i, j, argmax: integer;
sum, max: real;
S1: mas;
begin
ClrScr; {clearing screen}
for j := 1 to 6 do begin
WriteLn('Input ', j, ' column:');
for i := 1 to 4 do begin
ReadLn(S1[i,j]);
end;
end;
for j := 1 to 6 do begin
sum := 0;
for i := 1 to 4 do begin
sum := sum + S1[i,j];
end;
if j = 1 then begin
max := sum;
argmax := j;
end
else begin
if sum > max then begin
max := sum;
argmax := j;
end;
end;
end;
WriteLn('Column with maximum sum is ', argmax);
Write('Press any key to continue . . .');
ReadKey; {wait for the key pressing}
end.