Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Write a Matlab code to add numbers until the user enters zero using while loop?

1 回表示 (過去 30 日間)
Siddharth Pratyush
Siddharth Pratyush 2022 年 2 月 1 日
閉鎖済み: Cris LaPierre 2022 年 2 月 2 日
just give me simple code plss
  1 件のコメント
James Tursa
James Tursa 2022 年 2 月 1 日
What have you done so far? What specific problems are you having with your code?

回答 (2 件)

Walter Roberson
Walter Roberson 2022 年 2 月 1 日
There is no simple code for that. Your code needs to take into account these possibilities:
  • the user enters no input (just presses return)
  • the user enters a vector of numeric values, none of which is 0
  • the user enters a vector of numeric values, one of which is 0 -- not necessarily the last of them
  • the user enters a character vector or string or cell array or other non-numeric value
  • the user enters negative 0
  • the user enters different data types. For example if the user enters -3 +1 uint8(1) 0 then what result is to be expected ?

Image Analyst
Image Analyst 2022 年 2 月 1 日
編集済み: Image Analyst 2022 年 2 月 1 日
Hint:
theSum = 0
while something
thisNumber = input(..........)
% code
theSum = theSum + ..............
end
You should be able to figure it out. If you can't go over this before replying:
and this:

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by