Huw to create counter?

12 visualizaciones (últimos 30 días)
Anna Nordin
Anna Nordin el 3 de Sept. de 2019
Comentada: Adam Danz el 3 de Sept. de 2019
"Counters are useful programming tools, for example, to keep track of how many times a command has been executed. Create a counter in the variable r and set it to 1. Then write a loop that increases for each turn on the counter by one and then adds the value of the counter to a sum. Save the sum to the variable sum. The loop should go between 1 and 10"
I've gotten this task and the starting code below. But I don't understand what to do? (Just learning matlab)
r = ?
sum = +
for k = ?
r ?
sum?
end
  1 comentario
Anna Nordin
Anna Nordin el 3 de Sept. de 2019
Ops, here's the starting code again:
r = ?
summa = ?
for k=
r ?
summa ?
end

Iniciar sesión para comentar.

Respuesta aceptada

Anna Nordin
Anna Nordin el 3 de Sept. de 2019
r = 0
summa = 0
for k=1:10
r = r+1
summa = summa + r
end
  1 comentario
Adam Danz
Adam Danz el 3 de Sept. de 2019
That was my interpretation of the problem, too. Just be sure to never have a variable named "sum" as is written in the instructions.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by