Write a MATLAB function file that finds the greatest common

Write a MATLAB function file that finds the greatest common divisor of two integers. Your function definition line is given as follows: function gcd=find_gcd (a, b) where your input variables are integers a and b and your output argument is the returned result gcd. Test your function under the command window to find the gcd of 129 and 15.

Solution

function gcd1=find_gcd(a,b)

a1=a;b1=b;

while(a~=b)

if(a>b)

a=a-b;

else

b=b-a;

end

end

gcd1=a;

end

OUTPUT:

find_gcd(129,15)
ans =
3

>> find_gcd(100,75)
ans =
25

 Write a MATLAB function file that finds the greatest common divisor of two integers. Your function definition line is given as follows: function gcd=find_gcd (

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site