var ma: array of array of integer; n, m, i, j, max, maxi, maxj: integer; f: text; s, st: string;
begin randomize; readln(n); readln(m); max := -1; setlength(ma, n); for i := 0 to n - 1 do setlength(ma[i], m); writeln('Matrix:'); for i := 0 to n - 1 do begin writeln; for j := 0 to m - 1 do begin ma[i, j] := random(101); write(ma[i, j]:4); if max < ma[i, j] then begin max := ma[i, j]; maxi := i; maxj := j; end; end; end; assign(f, 'text.txt'); rewrite(f); for i := 0 to m - 1 do write(f, ma[maxi, i]:4); writeln(f, ' '); for i := 0 to n - 1 do write(f, ma[i, maxj]:4); close(f); writeln; writeln('File:'); assign(f, 'text.txt'); reset(f); while not Eof(f) do begin; readln(f, st); s := s + st + chr(10) + chr(13); end; close(f); write(s); end.
var
ma: array of array of integer;
n, m, i, j, max, maxi, maxj: integer;
f: text;
s, st: string;
begin
randomize;
readln(n);
readln(m);
max := -1;
setlength(ma, n);
for i := 0 to n - 1 do
setlength(ma[i], m);
writeln('Matrix:');
for i := 0 to n - 1 do
begin
writeln;
for j := 0 to m - 1 do
begin
ma[i, j] := random(101);
write(ma[i, j]:4);
if max < ma[i, j] then
begin
max := ma[i, j];
maxi := i;
maxj := j;
end;
end;
end;
assign(f, 'text.txt');
rewrite(f);
for i := 0 to m - 1 do
write(f, ma[maxi, i]:4);
writeln(f, ' ');
for i := 0 to n - 1 do
write(f, ma[i, maxj]:4);
close(f);
writeln;
writeln('File:');
assign(f, 'text.txt');
reset(f);
while not Eof(f) do
begin;
readln(f, st);
s := s + st + chr(10) + chr(13);
end;
close(f);
write(s);
end.
Пример ввода:
3
4
Пример вывода:
Matrix:
30 29 3 61
64 4 99 36
45 9 85 19
File:
64 4 99 36
3 99 85
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
int main()
{
int a, b, n;
cout <<"Введите границы диапазона и размер массива:" <<endl;
cin >>a >>b >>n;
if(n>10000) n=10000;
vector<int> v(n);
srand(time(0));
cout <<"Исходный массив:" <<endl;
for(int i=0; i<v.size(); ++i)
{
v[i] = rand()%(b-a+1) + a;
cout <<v[i] <<" ";
}
cout <<"\n3х-значные элементы, не кратные 5:" <<endl;
for (int i=0; i<v.size(); ++i)
if ((v[i]>99) && (v[i]<1000) && (v[i]%5!=0))
cout <<v[i] <<" ";
cout <<endl;
return 0;
}