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

 Respuesta aceptada

Jan
Jan el 30 de Nov. de 2020
Editada: Jan el 30 de Nov. de 2020
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.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Preguntada:

Liz
el 30 de Nov. de 2020

Comentada:

Liz
el 30 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by