Using fprintf to repeat the statement multiple times

33 次查看(过去 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