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

조회 수: 1 (최근 30일)
Abdur Rob
Abdur Rob 2020년 9월 26일
댓글: Abdur Rob 2020년 9월 26일
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개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by