how to write a script for multiplication table
Show older comments
I am wondering how to write a script that will print a multiplication table that looks like this: 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25
2 Comments
Adam
on 28 Oct 2015
What is the logic behind the sequence? Once you define that the rest is quite simple with
doc sprintf
to print out the numbers in whatever format you choose.
Ellis Fredella
on 28 Oct 2015
Answers (1)
Markus Pichler
on 28 Oct 2015
it seems that the sequence contains all the multiples of integers up to the square, i.e., in other form
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
and so forth
it will probably be more efficient with a loop, but you can also try
N = 5;
ix = [1:N].';
v = ix*ix.';
v(ix(:, ones(N, 1))<=ix(:, ones(N, 1)).').'
which throws away nearly half of the elements after generation
1 Comment
Ellis Fredella
on 28 Oct 2015
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!