1) var i, max, maxin: smallint; arr1, arr, sum: array[1..25] of smallint;
begin max := -(MaxSmallInt); randomize(); for i := 1 to 25 do begin arr[i] := Random(-100, 100); arr1[i]:=arr[i]; write(arr[i], ' '); while arr[i] <> 0 do begin sum[i] := abs(arr[i] mod 10) + sum[i]; arr[i] := arr[i] div 10; if sum[i] > max then begin max := sum[i]; maxin:=i; end; end; end; writeln(); writeln(arr1[maxin]); end.
2) var i, sum: byte; arr: array[1..20] of byte;
begin sum := 0; randomize(); for i := 1 to 20 do begin arr[i] := random(10); write(arr[i], ' '); if arr[i] = i then sum := i + sum; end; writeln(); writeln(sum); end.
#include <stdlib.h>
int main()
{
printf("Input of 10 elements on an interval [-10; 10]:\n");
int a = -10, b = 10, i, arr[10];
for(i = 0; i < 10; i++)
{
printf("\na[%d] = ", i);
scanf("%d", &arr[i]);
}
for(i = 0; i < 5; i++)
{
arr[i] = -arr[i];
}
for(i = 5; i < 10; i++)
{
arr[i] = -arr[i];
}
printf("\nMassiv with inversion:\n");
for(i = 0; i < 10; i++)
{
if(arr[i] >= a && arr[i] <= b)
{
printf("\na[%d] = %d", i, arr[i]);
}
else printf("\nError input");
}
return 0;
}
var
i, max, maxin: smallint;
arr1, arr, sum: array[1..25] of smallint;
begin
max := -(MaxSmallInt);
randomize();
for i := 1 to 25 do
begin
arr[i] := Random(-100, 100);
arr1[i]:=arr[i];
write(arr[i], ' ');
while arr[i] <> 0 do
begin
sum[i] := abs(arr[i] mod 10) + sum[i];
arr[i] := arr[i] div 10;
if sum[i] > max then begin
max := sum[i];
maxin:=i;
end;
end;
end;
writeln();
writeln(arr1[maxin]);
end.
2)
var
i, sum: byte;
arr: array[1..20] of byte;
begin
sum := 0;
randomize();
for i := 1 to 20 do
begin
arr[i] := random(10);
write(arr[i], ' ');
if arr[i] = i then sum := i + sum;
end;
writeln();
writeln(sum);
end.