フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Hola chicos necesito ayuda en este ejercicio 3

1 回表示 (過去 30 日間)
Chroma Prime
Chroma Prime 2018 年 10 月 26 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Make a program that graphs the letter ☒ of size n
  2 件のコメント
Steven Lord
Steven Lord 2018 年 10 月 26 日
Since this sounds like a homework assignment, if you show what you've tried so far and ask a specific question about where you're having difficulty we may be able to offer some guidance.
Chroma Prime
Chroma Prime 2018 年 10 月 26 日
編集済み: Steven Lord 2018 年 10 月 26 日
n=input('ingrese n')
a=fix(rand(n,n)*100)
for i=1:n
if(i==j)||(i+j==n+1)
fprintf('*')
else
fprintf(' ' )
end
end
fprintf('\n')
What I put is the programming to graph an x of any size, I would like to know how I would do so that this x is inside a square and any size, that is to say the one introduced
[SL: edited to apply code formatting. Chroma Prime, in the future before posting please select all your code and press the {} Code button. IMO it makes the code easier to read. Thanks.]

回答 (1 件)

Steven Lord
Steven Lord 2018 年 10 月 26 日
In your code, I suspect the second line (where you define the variable a) is left over from a previous attempt to solve the problem, as it's not used in the code.
Your loop is a good first step, but nowhere in your code do you define the variable j that you use. Because of that, MATLAB considers that to be a call to this function and i is never equal to sqrt(-1) so no stars get printed. You also have the printing of the newline after the end of the for loop, so even if it had printed the stars they'd all be on one line.
One common approach to solving this type of problem that I suspect your teacher/professor probably had in mind for you involves two loops. [I would avoid using i and j as the names of your loop variable names; row and col seem like more descriptive choices to me.] There are other techniques you could use, but that's probably the simplest.
If you want to put the X in a box, consider what rules the coordinates would have to satisfy for the point to be in the box. You already have two rules: (i == j) and (i+j == n+1). Add a couple more.

この質問は閉じられています。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by