Using fprintf to repeat the statement multiple times

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 日

0 投票

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.

1 件のコメント

Liz
Liz 2020 年 11 月 30 日
Oh that makes so much sense! Thanks so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2019b

質問済み:

Liz
2020 年 11 月 30 日

コメント済み:

Liz
2020 年 11 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by