Effacer les filtres
Effacer les filtres

Multiplication chart In MATLAB

1 vue (au cours des 30 derniers jours)
Larissa Monjaraz
Larissa Monjaraz le 12 Fév 2021
Commenté : Larissa Monjaraz le 12 Fév 2021
I need to make a multiplication chart like:
Size of multiplication chart: 3
1 2 3
2 4 6
3 6 9
I need it to adjust to any size multiplication table. I'm a beginner so some feedback would be nice, like where I went wrong.
Here's my code so far:
clc,clear;
S=input('Enter size of multiplication table: ');
R=1;
for ii = 1:S
for jj=1:S
fprintf('%g ', S*R)
R=R+1;
end
fprintf('\n');
end

Réponses (1)

James Tursa
James Tursa le 12 Fév 2021
Modifié(e) : James Tursa le 12 Fév 2021
You don't need R. Just multiply ii*jj. E.g.,
fprintf('%g ', ii*jj)
There are also ways to generate this table without any for-loops at all.
  1 commentaire
Larissa Monjaraz
Larissa Monjaraz le 12 Fév 2021
Thank you for the help!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by