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

1 Ansicht (letzte 30 Tage)
Abdur Rob
Abdur Rob am 26 Sep. 2020
Kommentiert: Abdur Rob am 26 Sep. 2020
N = 7;
for mm = 1:N
for nn = 1:mm
fprintf('*');
end
fprintf('\n');
end
out put is
*
**
***
****
*****
******
*******
********
but i want
*******
******
*****
****
***
**
*

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 26 Sep. 2020
Bearbeitet: Ameer Hamza am 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

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by