sum of 10-9+8+...+2-1 with results in the middle as follow. (Must use the repetition structure)
1 回表示 (過去 30 日間)
古いコメントを表示
How can I solve this problem with the loop?
sum of 10-9+8+...+2-1 with results in the middle as follow.
You must use the repetition structure.
10=10
10-9=1
10-9+8=9
.
.
.
10-9+8-7+6-5+4-3+2-1=5
The calculation process should also be shown in the command window.
3 件のコメント
Stephen23
2019 年 11 月 26 日
編集済み: Stephen23
2019 年 11 月 26 日
Original question at 2019-11-24 01:35:57:
"sum of 10-9+8+...+2-1 with results in the middle as follow with the loop"
sum of 10-9+8+...+2-1 with results in the middle as follow by using loop
10=10
10-9=1
10-9+8=9
.
.
.
10-9+8-7+6-5+4-3+2-1=5
Answer:
Revised question at 2019-11-24 02:31:23:
How can I solve this problem with the loop?
sum of 10-9+8+...+2-1 with results in the middle as follow.
You must use the repetition structure.
10=10
10-9=1
10-9+8=9
.
.
.
10-9+8-7+6-5+4-3+2-1=5
The calculation process should also be shown in the command window.
Revised question at 2019-11-24 06:14:08:
"How can I solve this problem?"
Sum of 10-9+...+2-1
回答 (1 件)
David Hill
2019 年 11 月 24 日
m=10;
[sprintf('%d',m),sprintf('=%d',sum(m))]
x=[];
for k=9:-1:1
x=[x,k*(-1)^k];
[sprintf('%d',m),sprintf('%+d',x),sprintf('=%d',10+sum(x))]
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!