フィルターのクリア

How do i write a script that will print the following multiplication table 1; 2 4; 3 6 9; 4 8 12 16; 5 10 15 20 25

10 ビュー (過去 30 日間)
Scott
Scott 2015 年 4 月 30 日
編集済み: Walter Roberson 2021 年 8 月 20 日
How do i write a script that will print the following multiplication table 1;2 4;3 6 9; 4 8 12 16; 5 10 15 20 25

回答 (4 件)

asma sarouji
asma sarouji 2018 年 11 月 2 日

Guillaume
Guillaume 2015 年 4 月 30 日
This looks like homework (and really easy at that), so here is a very simple solution that probably wouldn't be accepted for homework:
arrayfun(@(x) (1:x)*x, 1:5, 'UniformOutput', false); celldisp(ans)

PaulS
PaulS 2015 年 4 月 30 日
編集済み: Walter Roberson 2021 年 8 月 20 日
n=5
A=zeros(n)
for i=1:n
for j =1:n
if j<=i
A(i,j)=i*j
end
end
end
  2 件のコメント
Scott
Scott 2015 年 4 月 30 日
Awesome! How do you display this answer so that it prints it in a matrix form?
Aitazaz Ahsan
Aitazaz Ahsan 2021 年 8 月 20 日
There is already a matrix with all entries equal to zero so in for loop only the concerned entries are changing and which will give the desired solution inmatrix form.

サインインしてコメントする。


Tony Nguyen
Tony Nguyen 2021 年 8 月 15 日
clc;
clear all;
for i = 1:5
fprintf('%4d',i*[1:i])
fprintf('\n')
end

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by