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 functionExplanation / 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)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.