Help.. how would i get 7* to 1*

1 view (last 30 days)
Abdur Rob
Abdur Rob on 26 Sep 2020
Commented: Abdur Rob on 26 Sep 2020
N = 7;
for mm = 1:N
for nn = 1:mm
fprintf('*');
end
fprintf('\n');
end
out put is
*
**
***
****
*****
******
*******
********
but i want
*******
******
*****
****
***
**
*

Accepted Answer

Ameer Hamza
Ameer Hamza on 26 Sep 2020
Edited: Ameer Hamza on 26 Sep 2020
You can run the for-loop in reverse order too
N = 7;
for mm = N:-1:1 % equivalent to mm = flip(1:N)
for nn = 1:mm
fprintf('*');
end
fprintf('\n');
end

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!