Q - Write a piece of code that will sum all the numbers between 1 and abcd.
a = 8 b = 8 c = 3 d =1
New to MatLab and am struggling with this one, hope you can help!
Thanks

6 件のコメント

the cyclist
the cyclist 2020 年 3 月 18 日
For homework help, please post what you have tried, and ask specific questions about where you are stuck. That way we can help in ways that are not simply doing your homework for you.
If you have literally no idea on how to start, I would recommend going to your instructor.
David Hill
David Hill 2020 年 3 月 18 日
between 1 and 8831?
Joshua Jones
Joshua Jones 2020 年 3 月 18 日
for ii = 1:(a*b*c*d)
my_sum = my_sum + ii
end
my_sum = 18528
is this correct?
Ameer Hamza
Ameer Hamza 2020 年 3 月 18 日
Joshua, I guess the actual question regards abcd as consecutive digits rather than a*b*c*d. So you have to find a way to make
a = 8;
b = 8;
c = 3;
d = 1;
into 8831.
Adam Danz
Adam Danz 2020 年 3 月 18 日
Joshua Jones , based on your previous comment, you want to sum all values from 1 to (8*8*3*1), or, from 1:192. Is that correct?
If so, no loop needed.
my_sum = sum(1:a*b*c*d)
Joshua Jones
Joshua Jones 2020 年 3 月 18 日
Hi, yeah that works perfectly!
Thank you

サインインしてコメントする。

 採用された回答

Adam Danz
Adam Danz 2020 年 3 月 18 日

0 投票

no loop needed.
my_sum = sum(1:a*b*c*d)

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGeneral Applications についてさらに検索

製品

タグ

質問済み:

2020 年 3 月 18 日

回答済み:

2020 年 3 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by