Discrete math
1) Using MatLab (any language is fine just saywhat language is used).
function d=lemma_gcd(a,b)
%This program will return the greatest common divisor for inputvariables a
%and b where a and b are integers such that they are not both 0. Ituses
%Lemma 4.8.3 on page 225.
%Note: gcd(a,b)=gcd(-a,b)=gcd(a,-b)=gcd(-a,-b), so
a=abs(a);
b=abs(b);
%This following section sets up the arrays we will use to storethe
%changing values of our variables as a sequence. "c" will be thecount
%variabe, stored in "C", "a" and "b" will also bechanging andstored in "A"
%and "B" arrays through the iterations of the loops.
c=0;
C(1)=c; %Stores c=0 in the array, C
%Next find the initial a and b to kick the program into gear
if a==0 & b==0
fprintf('You cannot input these variables')
d=inf;
else
if floor(a)~=a
fprintf('You cannot input these variables')
d=inf;
if floor(b)~=b
fprintf('You cannot input these variables')
d=inf;
end
end
end