Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

( Greatest Common Divisor - Recursive Method ) Show all steps to use the pseudo

ID: 3776646 • Letter: #

Question

( Greatest Common Divisor - Recursive Method )

            Show all steps to use the pseudo - code segment below to find the return value of the following call to recursive function GCD() .          GCD(24, 56)

            FUNCTION GCD(parameter a, parameter b)

          IF (b == 0) THEN
             result a
          ELSE
             result GCD(b, a MOD b)

           END IF


          END FUNCTION

(1) Greatest Common Divisor Recursive Method Show all steps to use the pseudo Code segment below to find the return value of the following call to recursive function GCDO. GCD (24 56) FUNCTION GCD (parameter a parameter b) IF (b 0) THEN result a ELSE result GCD (b, a MOD b) END IF END FUNCTION

Explanation / Answer

public class Divisor {

   public static void main(String[] args) {
       int a=24, b=56;
       System.out.println("GCD of 24, 56 = "+GCD(a, b));
      
   }
  
  
   public static int GCD(int a, int b) {
       if(b==0)return a;
       else {
           a=a%b;
           return GCD(b, a);
       }
   }

}