"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

Ops, here's the starting code again:
r = ?
summa = ?
for k=
r ?
summa ?
end

댓글을 달려면 로그인하십시오.

 채택된 답변

Anna Nordin
Anna Nordin 2019년 9월 3일

0 개 추천

r = 0
summa = 0
for k=1:10
r = r+1
summa = summa + r
end

댓글 수: 1

Adam Danz
Adam Danz 2019년 9월 3일
That was my interpretation of the problem, too. Just be sure to never have a variable named "sum" as is written in the instructions.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2019년 9월 3일

댓글:

2019년 9월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by