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

MATHLAB PROGRAMMING Your task is to implement GCD functions with the following s

ID: 3923484 • Letter: M

Question

MATHLAB PROGRAMMING Your task is to implement GCD functions with the following signature. function d = gcd_iterative(x, y) function d = gcd_recursive(x, y) Argument x is a nonnegative integer. Argument y is a nonnegative integer. This is how your function must be implemented: The gcd_iterative function must be implemented with iteration (a loop). The gcd_recursive function must be implemented with recursion. You may use Matlab's builtin mod function. You must not use any other builtin functions: e.g., Matlab already has a gcd function MATHLAB PROGRAMMING Your task is to implement GCD functions with the following signature. function d = gcd_iterative(x, y) function d = gcd_recursive(x, y) Argument x is a nonnegative integer. Argument y is a nonnegative integer. This is how your function must be implemented: The gcd_iterative function must be implemented with iteration (a loop). The gcd_recursive function must be implemented with recursion. You may use Matlab's builtin mod function. You must not use any other builtin functions: e.g., Matlab already has a gcd function MATHLAB PROGRAMMING Your task is to implement GCD functions with the following signature. function d = gcd_iterative(x, y) function d = gcd_recursive(x, y) Argument x is a nonnegative integer. Argument y is a nonnegative integer. This is how your function must be implemented: The gcd_iterative function must be implemented with iteration (a loop). The gcd_recursive function must be implemented with recursion. You may use Matlab's builtin mod function. You must not use any other builtin functions: e.g., Matlab already has a gcd function

Explanation / Answer

recursive gcd:-

function [value] = GCD(a,b)
if b == 0
value = a;
return
else
value = GCD(b,mod(a,b);
return
end
end

iterative gcd:-

clc;
clear all;
close all;
a=input('Enter the first number:- ');
b=input('Enter the second number:- ');
while(a~=b)
if(a>b)
a=a-b;
else
b=b-a;
end
end
disp('GCD of given numbers is:- ');
disp(a)