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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by