Trying to print a triangle on screen

4 次查看(过去 30 天)
I'm trying to print a triangle like this
but i get this
my code works to make the triangle, but i need it flipped. what part of my code do i edit to do this
n=input('How many rows for right justified triangle do you want ');
for i=2:n+1
for j=1:i-1
fprintf('*');
fprintf('');
end
fprintf('\n');
end

采纳的回答

KSSV
KSSV 2018-5-3
n=input('How many rows for right justified triangle do you want ');
for i=1:n
str = [blanks(n-i) repelem('*',1,i)] ;
fprintf('%s\n',str) ;
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by