필터 지우기
필터 지우기

For loop comand use

조회 수: 1 (최근 30일)
F.O
F.O 2017년 10월 5일
댓글: F.O 2017년 10월 6일
Hi,I want to compute the sum 2 + 4 + 6 + 8 + 10 + : : : + 100 by using For loop . Can anyone here thankfully help me out?
  댓글 수: 4
James Tursa
James Tursa 2017년 10월 5일
편집: James Tursa 2017년 10월 5일
Change
total = total + 1;
to
total = total + k; % <-- You need to add the index variable k, not 1 every time
F.O
F.O 2017년 10월 6일
I have changed it and got correct answer. Thanks

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

채택된 답변

James Tursa
James Tursa 2017년 10월 5일
The general outline of your for loop would be:
total = 0;
for k=start_value:increment:end_value % <-- you fill in the start_value, increment, and end_value
total = total + something; % <-- you fill in the something
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by