Var a:array[1..100] of integer; n,i,k,c:integer; begin Randomize; write('n = '); readln(n); Writeln('Исходный массив:'); for i:=1 to n do begin a[i]:=random(100); write(a[i]:6); end; writeln; for k := 1 to n-1 do for i := n-1 downto k do if a[i] > a[i+1] then begin c:=a[i]; a[i]:=a[i+1]; a[i+1]:=c end; Writeln('Отсортированный массив:'); for i:=1 to n do write(a[i]:6); writeln; end.
#include <iostream>
using namespace std;
int main()
{
int n, m;
int **arr;
int min;
cout << "Enter dimension of array (n/m)" << endl;
cin >> n >> m;
arr = new int *[n];
for (int i = 0; i < n; i++) {
arr[i] = new int[m];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << "arr[" << i << "][" << j << "] = ";
cin >> arr[i][j];
}
}
cout << "Your array:" << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cout << arr[i][j] << " ";
}
cout << endl;
}
cout << "Min is: ";
min = arr[0][0];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (min > arr[i][j]) {
min = arr[i][j];
}
}
}
cout << min << endl;
return 0;
}
n,i,k,c:integer;
begin
Randomize;
write('n = '); readln(n);
Writeln('Исходный массив:');
for i:=1 to n do begin
a[i]:=random(100);
write(a[i]:6);
end;
writeln;
for k := 1 to n-1 do
for i := n-1 downto k do
if a[i] > a[i+1] then
begin
c:=a[i];
a[i]:=a[i+1];
a[i+1]:=c
end;
Writeln('Отсортированный массив:');
for i:=1 to n do write(a[i]:6);
writeln;
end.
Пример:
n = 15
Исходный массив:
10 0 59 85 98 71 72 55 29 50 54 27 34 56 73
Отсортированный массив:
0 10 27 29 34 50 54 55 56 59 71 72 73 85 98