I have the following code
function output=beautyofmath(i)for i = 1:9 if i == 1 j(i, 1) = i; else j(i, 1) = j(i - 1, 1) * 10 + i; end j(i, 2) = i; j(i, 3) = j(i, 1) * 8 + j(i, 2); fprintf('%d x 8 + %d = %d\n', j(i, 1), j(i, 2), j(i, 3)); end
The problem is it outputs the following no matter the i value. If I type in beautyofmath(5), I only want the first 5 values to show up. How do I fix this?
1 x 8 + 1 = 912 x 8 + 2 = 98123 x 8 + 3 = 9871234 x 8 + 4 = 987612345 x 8 + 5 = 98765123456 x 8 + 6 = 9876541234567 x 8 + 7 = 987654312345678 x 8 + 8 = 98765432123456789 x 8 + 9 = 987654321
Best Answer