Var i, j, max, n, m: integer; ar: array[,]of integer; begin readln(n, m); setlength(ar, n, m); for i := 0 to n - 1 do for j := 0 to m - 1 do ar[i, j] := random(0, 100); max := ar[0, 0]; for i := 0 to n - 1 do begin for j := 0 to m - 1 do begin if(ar[i, j] > max) then max := ar[i, j]; end; end; writeln('Максимальный элемент: ', max); for i := 0 to n - 1 do begin for j := 0 to m - 1 do write(ar[i, j]:4, ' '); writeln; end; end.
float average(int* a, int first, int last) { int s = 0; for(int i = first; i <= last; ++i) s += a[i]; return s * 1. / (last - first + 1); } int min_i(int* a, int n) { int m = a[0]; int numb = 0; for(int i = 1; i < n; ++i) if(m > a[i]) { m = a[i]; numb = i; } return numb; } int max_i(int* a, int n) { int m = a[0]; int numb = 0; for(int i = 1; i < n; ++i) if(m < a[i]) { m = a[i]; numb = i; } return numb; } int main() { int N; std::cin >> N; int X[N]; for(int i = 0; i < N; ++i) std::cin >> X[i]; std::cout << "Average of whole array: " << average(X, 0, N - 1) << std::endl; int first = min_i(X, N); int last = max_i(X, N); if(first > last) { int temp = first; first = last; last = temp; } if(last - first == 0 || last - first == 1) std::cout << "Average of shorter array: " << average(X, 0, N - 1) << std::endl; else { int delta = last - first; for(int i = last; i < N; ++i) X[i - delta + 1] = X[i]; std::cout << "Average of shorter array: " << average(X, 0, N - delta) << std::endl; } }
i, j, max, n, m: integer;
ar: array[,]of integer;
begin
readln(n, m);
setlength(ar, n, m);
for i := 0 to n - 1 do
for j := 0 to m - 1 do ar[i, j] := random(0, 100);
max := ar[0, 0];
for i := 0 to n - 1 do
begin
for j := 0 to m - 1 do
begin
if(ar[i, j] > max) then max := ar[i, j];
end;
end;
writeln('Максимальный элемент: ', max);
for i := 0 to n - 1 do
begin
for j := 0 to m - 1 do write(ar[i, j]:4, ' ');
writeln;
end;
end.
float average(int* a, int first, int last)
{
int s = 0;
for(int i = first; i <= last; ++i)
s += a[i];
return s * 1. / (last - first + 1);
}
int min_i(int* a, int n)
{
int m = a[0];
int numb = 0;
for(int i = 1; i < n; ++i)
if(m > a[i])
{
m = a[i];
numb = i;
}
return numb;
}
int max_i(int* a, int n)
{
int m = a[0];
int numb = 0;
for(int i = 1; i < n; ++i)
if(m < a[i])
{
m = a[i];
numb = i;
}
return numb;
}
int main()
{
int N;
std::cin >> N;
int X[N];
for(int i = 0; i < N; ++i)
std::cin >> X[i];
std::cout << "Average of whole array: " << average(X, 0, N - 1) << std::endl;
int first = min_i(X, N);
int last = max_i(X, N);
if(first > last)
{
int temp = first;
first = last;
last = temp;
}
if(last - first == 0 || last - first == 1)
std::cout << "Average of shorter array: " << average(X, 0, N - 1) << std::endl;
else
{
int delta = last - first;
for(int i = last; i < N; ++i)
X[i - delta + 1] = X[i];
std::cout << "Average of shorter array: " << average(X, 0, N - delta) << std::endl;
}
}