Write a MATLAB script that asks the user to input two nonneg
Write a MATLAB script that asks the user to input two non-negative integers (not both zero), checks that the inputs are valid, and computes the GCD using the Euclidean Algorithm. Take pictures of output and type .m file.
Solution
% Screen is cleared and all the variables are deleted
clear; clc
% Used will be asked for inputs and only positive inputs will be permitted
a = input(\'First number: \');
b = input(\'Second number: \');
a = abs(a);
b = abs(b);
% This is the main operation to conduct the series of sub operations which later leads to finding gcd
r = a - b*floor(a/b);
% Same operation is repeated numerous times until a equal to dummy b
while r ~= 0
a = b;
b = r;
r = a - b*floor(a/b);
end
% Result is displayed
GCD = b
