Write an algorithm that outputs the smallest element in the sequence: SÃ ¢ , S2... Sn Use the procedure name find_small and output small. Make a recursive algorithm for finding the greatest common divisor of any non-negative integers a and b, where a and b are both not equal to zero. Use the procedure name gcd_recurs.
The Answer to the Question
is below this banner.
Can't find a solution anywhere?
NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?
Get the Answers Now!You will get a detailed answer to your question or assignment in the shortest time possible.
Here's the Solution to this Question
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