Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
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'.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Iman Ansari
el 9 de Mayo de 2013
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
0 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!