Use a for loop to determine the sum of the first ten even terms in the series 5k3 (k=2, 4, 6, ….)

11 ビュー (過去 30 日間)
Tika
Tika 2022 年 10 月 20 日
編集済み: James Tursa 2022 年 10 月 20 日
I have the following but shows error. Please help
for k=2:10
total=5.*k^3;
end
disp('sum of the first ten even terms is: ')
disp(total)

回答 (1 件)

James Tursa
James Tursa 2022 年 10 月 20 日
編集済み: James Tursa 2022 年 10 月 20 日
You are summing all the terms with 2:10. For the "even" terms you need to skip the odd ones, so the range would be 2:2:something (the middle 2 means every other value starting at 2). You just need to figure out what the "something" value is in order to get ten even terms.

カテゴリ

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