Using fprintf to repeat the statement multiple times

조회 수: 33 (최근 30일)
Liz
Liz 2020년 11월 30일
댓글: Liz 2020년 11월 30일
The question is:
Prompt the user for an integer n and print "I love this stuff!" n times.
I thought I went around it by doing this: however I am not sure where to put the n number in and how to do it.
>> for iv = 1:n
inputnum = input('Enter a integer: ');
fprintf('I love this stuff')
end

채택된 답변

Jan
Jan 2020년 11월 30일
편집: Jan 2020년 11월 30일
Almost working.
n = input('Enter a integer: ');
for k = 1:n
fprintf('I love this stuff\n')
end
Ask for n before the loop, not inside.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by