Sum and average even numbers
10 次查看(过去 30 天)
显示 更早的评论
Write a code that can add all the even numbers less than and including 50 and to find their average.
You can use the basic loop commands,colon operators and basic arithmetic operators.
10 个评论
Walter Roberson
2011-4-15
There is are some serious questions here suitable for implementation in MATLAB. See the following for details of calculations:
http://www.style.org/unladenswallow/
回答(4 个)
Matt Tearle
2011-4-14
Why bother? The answer is -Inf. Your teacher needs to write more precise questions.
4 个评论
Walter Roberson
2011-4-16
MATLAB doesn't have any negative integers below -realmax so adding the ones "up to -realmax" is going to get you -realmax .
It is not a priori obvious that one would get -inf rather than nan or some other value when doing the calculation you were probably thinking of, so doing the calculation does become worthwhile.
Matt Tearle
2011-4-18
Hah. I just realized that, in my mind, a:dx:b goes "up to b", even if dx < 0. Stupid semantics.
Jan
2011-4-15
The famous Mr. Gauss could solve these calculations in some seconds without a computer. He imagined a table with the largest and smallest element sided by side, and the 2nd largest and 2nd smallest, etc. How many such pairs can you create? How large is the sum of these two elements? Are you able to ask Wikipedia how to use these information to creatre your answer with "basic arithmetic operators" only?
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!