Sum and average even numbers

9 Ansichten (letzte 30 Tage)
NONE NONE
NONE NONE am 14 Apr. 2011
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 Kommentare
Matt Fig
Matt Fig am 15 Apr. 2011
@Matt,
http://bottlecollecting.blogspot.com/
Walter Roberson
Walter Roberson am 15 Apr. 2011
There is are some serious questions here suitable for implementation in MATLAB. See the following for details of calculations:
http://www.style.org/unladenswallow/

Melden Sie sich an, um zu kommentieren.

Antworten (4)

Matt Tearle
Matt Tearle am 14 Apr. 2011
Why bother? The answer is -Inf. Your teacher needs to write more precise questions.
  4 Kommentare
Walter Roberson
Walter Roberson am 16 Apr. 2011
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
Matt Tearle am 18 Apr. 2011
Hah. I just realized that, in my mind, a:dx:b goes "up to b", even if dx < 0. Stupid semantics.

Melden Sie sich an, um zu kommentieren.


Paulo Silva
Paulo Silva am 14 Apr. 2011
  2 Kommentare
Sean de Wolski
Sean de Wolski am 14 Apr. 2011
That's a pretty sweet emoticon. A cyclops with a button down suit?
Paulo Silva
Paulo Silva am 14 Apr. 2011
lol that's funny, it does look weird and cool at the same time :)

Melden Sie sich an, um zu kommentieren.


Jan
Jan am 15 Apr. 2011
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?

Sean de Wolski
Sean de Wolski am 14 Apr. 2011
Okay, I wrote it. Can I have a beer now?
  5 Kommentare
Sean de Wolski
Sean de Wolski am 14 Apr. 2011
Matt, I thought that was one of the conditions of solving a doit4me?
Oleg Komarov
Oleg Komarov am 14 Apr. 2011
Doh...

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by