Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { ... find the sum of all elements behind (after) first maximum element. Display a message if there are none. }
- const n = 6;
- var m: array[1 .. n] of Integer;
- i, mxIndex, mxValue, sum: Integer;
- begin
- { input }
- for i := 1 to n do begin
- write('M[', i, '] = ');
- readLn(M[i]);
- end;
- { find max }
- mxIndex := 0;
- mxValue := 0;
- for i := 1 to n do begin
- if (mxIndex = 0) or (M[i] > mxValue) then begin
- mxIndex := i;
- mxValue := M[i];
- end;
- end;
- { sum-related }
- if (mxIndex < n) then begin
- sum := 0;
- for i := mxIndex + 1 to n do sum := sum + M[i];
- writeLn('Sum: ', sum);
- end else writeLn('There are no elements behind the maximum');
- end.
Advertisement
Add Comment
Please, Sign In to add comment