Discrete Mathematics and Its Applications Chapter 31 problem
Discrete Mathematics and Its Applications: Chapter 3.1 problem 20
Describe an algorithm for finding the largest and the smallest integers in a finite sequence of integers.
Solution
The following will be the algorithm
Maxmin(array,n)
define max = array[1];
define min = array[1];
for(i=2;i<n;i++)
begin
if(max < array[i])
max = array[i];
if(min > array[i])
min = array[i];
end;
print the max and min which contains the maximum and minimum values of the finite sequence of integers
