#include <iostream>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[100][100];
// чтение
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
int max = a[0][0], max_i = 0, max_j = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] > max) {
max = a[i][j];
max_i = i;
max_j = j;
}
}
}
cout << max_i << " " << max_j;
return 0;
}
Объяснение:
program max_elementarray ;
var i, max : integer ;
a : array [1..10] of integer;
begin
for i : = 1 to 10 do
begin
readln(a[i]);
end;
max : = a[1];
for i : = 2 to 10 do
if a[i]> max then max : = a[i];
writeln('max element of array = ',max) ;
readln ;
end.
Поделитесь своими знаниями, ответьте на вопрос:
Дан массив из n элементов. найти сумму отрицательных элементов с четными индексами и отдельно с нечетными. (паскаль) 9 класс
begin
readln(n);
s1:=0;
s2:=0;
for i:=1 to n do read(a[i]);
for i:=1 to n do begin
if (a[i]<0) and (i mod 2=0) then s1:=s1+a[i]
end;
for i:=1 to n do begin
if (a[i]<0) and (i mod 2<>0) then s2:=s2+a[i]
end;
writeln(s1);
writeln(s2);
end.