MATHLAB PROGRAMMING Your task is to implement GCD functions

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

Solution

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)

 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) Arg
 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) Arg

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site