using For loop to represent positive intergers with the corresponding #. And modifying the script to write out a triangular pattern with a decreasing number of #'s on each successive line

% a script which reads in a positive integer
% and writes out the corresponding number of “#” characters on one line
num=1;
fprintf('This program reads any positive integer');
while num>0
% print out corresponding number of #'s char on one line
fprintf('%d\n', num);

답변 (1개)

Thorsten
Thorsten 2015년 11월 11일
편집: Thorsten 2015년 11월 11일
Use input to get number, and repmat to replicate '#' number times. To count down, use
for i=num:-1:1
To display num #'s use
disp(repmat('#', 1, num))
I think these are enough hints to complete the task yourself.

이 질문은 마감되었습니다.

질문:

2015년 11월 11일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by