Find Maximum Value Input: An array of numbers, arr
1. If arr is empty, return an error or a special value indicating no maximum.
2. Set max_value to the first element of arr (arr[0]).
3. For each element num in arr starting from the second element (index 1):
a. If num is greater than max_value, update max_value to num.
4. Return max_value as the maximum value in the array. Example: arr = [5, 2, 9, 1, 5, 6]
Result: The maximum value is 9.
No comments:
Post a Comment