For the first question. To outputs the smallest element in the sequence.
Input: The sequence s1, s2,...,sn and the length n of the sequence
Output: small, the smallest element in this sequence
procedure find_small(s, n)
small := s_1
i := 2
while i ≤ n do
begin
if s_i < small then // a smaller value was found
small := s_i
i := i + 1
end
return(small)
end find_small
For the second question. To find GCD.
procedure gcd_recurs(a, b)
begin
if b = 0 then
return x;
else
call: gcd_recurs(b, a%b);
endif
end
Comments
Leave a comment