Info

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

Write a function getatriangle(R,f,b) that takes the number of rows R and returns a character matrix that has the shape of a triangle filled with the character 'f' on a background filled with the character 'b'.

2 ビュー (過去 30 日間)
Sean
Sean 2013 年 5 月 7 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Assume that R is a positive integer and that f and b are single characters. If b is not given, use '.' . If f is not given, use '#'.
Ex
>>getatriangle(4,'@','-')
ans =
---@---
--@@@--
-@@@@@-
@@@@@@@
>> getatriangle(5)
ans =
....#....
...###...
..#####..
.#######.
#########
  2 件のコメント
Matt Kindig
Matt Kindig 2013 年 5 月 7 日
Your output looks good. What is your question?
Sean
Sean 2013 年 5 月 7 日
how to write the function haha. so far i have:
function t = getatriangle(R,f,b)
if nargin == 1;
f = '#';
b = '.';
end

回答 (1 件)

Iman Ansari
Iman Ansari 2013 年 5 月 9 日
Hi.
R = 20;
f = '@';
b = '-';
max_num=2*R-1;
fprintf('\n');
for i=1:R
S1=repmat(b,[1 R-i]);
S2=repmat(f,[1 2*i-1]);
S=[S1 S2 S1];
fprintf('%s\n',S);
end

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

Community Treasure Hunt

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

Start Hunting!

Translated by