var a: array[1..MAX_SIZE] of integer; i, size: integer;
procedure delete_odd_elements(); var i, j: integer; begin i := 1; repeat if odd(a[i]) then begin dec(size); for j := i to size do a[j] := a[j + 1] end else inc(i); until i > size; end;
begin writeln('Исходный массив: '); size := MAX_SIZE; for i := 1 to size do begin a[i] := random(100); write(a[i] : 3); end; delete_odd_elements; writeln; writeln('Полученный массив: '); for i := 1 to size do write(a[i] : 3); end.
#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;
int main (void)
{
srand (time (0));
int Temp = 0;
int max = 1;
int maxi = 0;
int n = 0;
cout << "Input n = ";
cin >> n;
cout << endl;
int *A = new int[n];
for (int i = 0; i < n; i++)
{
A[i] = -10 + rand () % 30;
cout << A[i] << " ";
}
for (int i = 0; i < n; i++)
{
if (abs (A[i]) > abs (max))
{
max = A[i];
maxi = i;
}
}
cout << "\nABS(Max) = " << max << " Number = " << maxi;
Temp = A[n - 1];
A[n - 1] = max;
A[maxi] = Temp;
cout << endl;
for (int i = 0; i < n; i++)
{
cout << A[i] << " ";
}
delete[]A;
}
Объяснение:
MAX_SIZE = 10;
var
a: array[1..MAX_SIZE] of integer;
i, size: integer;
procedure delete_odd_elements();
var i, j: integer;
begin
i := 1;
repeat
if odd(a[i]) then
begin
dec(size);
for j := i to size do
a[j] := a[j + 1]
end
else inc(i);
until i > size;
end;
begin
writeln('Исходный массив: ');
size := MAX_SIZE;
for i := 1 to size do
begin
a[i] := random(100);
write(a[i] : 3);
end;
delete_odd_elements;
writeln;
writeln('Полученный массив: ');
for i := 1 to size do
write(a[i] : 3);
end.