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
조회 수: 11 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (4개)
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)
댓글 수: 0
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
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!