Mathlab program solving answr below

I want me to reVerse out put what will Be the math lab program looK Like,
n=5
n = 5
for i=1:n
for j=1:i
fprintf('%d', i)
end
fprintf('\n')
end
122333444455555

7 件のコメント

Steven Lord
Steven Lord 2022 年 8 月 20 日
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.
Hakim
Hakim 2022 年 8 月 20 日
編集済み: Rik 2022 年 8 月 20 日
Here is my code I want reverse Output
n=5
for i=1:n
for j=1:i
fprintf('%d', i)
end
fprintf('\n')
end
dpb
dpb 2022 年 8 月 20 日
What do you expect output to be? What's the purpose of the second loop over j; nothing in the loop is dependent upon it?
See doc at <for> for (so to speak :) ) the ways to write loop indexing expressions; it has example of interest as about the 2nd one, iirc. Alternatively, look at flip and friends and see if that gives you any other ideas...
Hakim
Hakim 2022 年 8 月 20 日
I want to reverse out put of this code
Torsten
Torsten 2022 年 8 月 20 日
編集済み: Torsten 2022 年 8 月 20 日
I generated your output above. Could you write down what you want instead of
122333444455555
?
Hakim
Hakim 2022 年 8 月 20 日
5 4 4 3 3 3 2 2 2 2 1 1 1 1 1
Hakim
Hakim 2022 年 8 月 20 日
編集済み: John D'Errico 2022 年 8 月 21 日
(By now, you should understand the difference between a comment and an answer. I moved your answer to a comment.)
I want 5 4 4 3 3 3 2 2 2 2 1 1 1 1 1

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

回答 (2 件)

Jan
Jan 2022 年 8 月 20 日

0 投票

Maybe you want to replace
for i = 1:n
by
for i = n:-1:1
Torsten
Torsten 2022 年 8 月 20 日
移動済み: Image Analyst 2022 年 8 月 21 日

0 投票

n = 5;
for i=n:-1:1
for j=n:-1:i
fprintf('%d', i)
end
fprintf('\n')
end
544333222211111

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2022 年 8 月 20 日

移動済み:

2022 年 8 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by