Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program LocalMaximums;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- const
- N = 24;
- type
- TArray = array[1..N] of Integer;
- procedure InputOfArray(var X: TArray);
- var
- i: Integer;
- begin
- for i := 1 to N do
- X[i] := Random(100) - 50;
- end;
- procedure OutputOfArray(var X: TArray);
- var
- i: Integer;
- begin
- Writeln('Initial array: ');
- for i := 1 to N do
- Write(X[i], ' ');
- Writeln; Writeln;
- end;
- function MaximumOfArray(X: TArray): Integer;
- var
- i, Max: Integer;
- begin
- Max := X[1];
- for i := 2 to N do
- if X[i] > Max then
- Max := X[i];
- MaximumOfArray := Max;
- end;
- procedure OutputOfLocalMaximums(X: TArray);
- var
- i, Max: Integer;
- begin
- Writeln('Local maximum indexes: ');
- Max := MaximumOfArray(X);
- for i := 2 to N - 1 do
- begin
- if (X[i] <> Max) and ((X[i] > X[i - 1]) and (X[i] > X[i + 1])) then
- write(i, ' ');
- end;
- end;
- var
- D: TArray;
- begin
- InputOfArray(D);
- OutputOfArray(D);
- OutputOfLocalMaximums(D);
- ReadLn;
- end.
Add Comment
Please, Sign In to add comment