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

2 次查看(过去 30 天)
N = 7;
for mm = 1:N
for nn = 1:mm
fprintf('*');
end
fprintf('\n');
end
out put is
*
**
***
****
*****
******
*******
********
but i want
*******
******
*****
****
***
**
*

采纳的回答

Ameer Hamza
Ameer Hamza 2020-9-26
编辑:Ameer Hamza 2020-9-26
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by