TASK 2 2 MARKS -L06D] Write a script using loops to produce the following output
ID: 3703496 • Letter: T
Question
TASK 2 2 MARKS -L06D] Write a script using loops to produce the following output. Ask the user for a maximum number of iterations (n). The script should iterate from 1 to n to produce the expressions on the left, perform the specified operation to get the results shown on the right, and print using the format shown (for n-11) Use fprintf to produce the statements. 1 x 8+1-9 12 x 8 + 2 = 98 123 x 8+3-987 1234 x 8 +4 9876 12345 x 8 + 5 = 98765 123456 x 8 6 987654 1234567 x 8 + 7 = 9876543 12345678 x 8 + 8 = 98765432 123456789 x 8 + 9 987654321 1234567900 x 8 + 10 = 9876543210 12345679011 x 8 + 11 98765432099 Note: You must use loops.Explanation / Answer
MATLAB SCRIPT
function t=show(n) % create function show()
k=8; % initialize k=8
p=1; % initialize p=1
% create for loop until n
for i=1:n
x=i; % assign i to x
fprintf(" %d x %d + %d = %d",p,k,x,p*k+x) % display actual format
p=p*10+i+1; % calculate p value to print 1,12,123...
end
end
OUTPUT
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.