Trying to print a triangle on screen
4 views (last 30 days)
Show older comments
I'm trying to print a triangle like this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/190271/image.png)
but i get this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/190272/image.png)
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
0 Comments
Accepted Answer
KSSV
on 3 May 2018
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 Comments
More Answers (0)
See Also
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!