TASK: Print greatest common divisor tables.
COMMENT: The greatest common divisor of integers I and J is the largest integer K that evenly divides them both. We write "k = gcd(i,j)" to indicate this. For instance, gcd(14,35)=7, gcd(23,22)=1, and gcd(97,97)=97.
We want to print out a GCD table for all pairs of numbers between P and Q. For instance, if P = 1 and Q = 4, we want a table that shows the VALUES of the following quantities:
gcd(1,1) gcd(1,2) gcd(1,3) gcd(1,4)
gcd(2,1) gcd(2,2) gcd(2,3) gcd(2,4)
gcd(3,1) gcd(3,2) gcd(3,3) gcd(3,4)
gcd(4,1) gcd(4,2) gcd(4,3) gcd(4,4)
INSTRUCTIONS:
Use MATLAB's input() statement to request values for p and q.
Use a for loop, with counter "i" running from p to q,
to handle each row.
Inside of that loop, use another for loop, with counter "j",
also running from p to q, to deal with each column.
Print the value of gcd(i,j). Use an fprintf() statement
that does NOT include a "new line" symbol, like this:
fprintf ( ' %d', gcd(i,j) );
end the inner "j" loop.
Terminate this row with a "new line".
fprintf ( '\n' );
end the outer "i" loop.
CHECK: If P = 1 and Q = 4, your program should print out:
1 1 1 1
1 2 1 2
1 1 3 1
1 2 1 4
SUBMIT: Your work should be stored in a script file called "hw016.m". Your script file should begin with at least three comment lines:
% hw016.m
% YOUR NAME
% This script (describe what it does)
% Add any comments here that you care to make.
If this problem is part of an assignment, then submit it to Canvas.