Sum and average even numbers

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 comentarios

Oleg Komarov
Oleg Komarov el 14 de Abr. de 2011
Go for it dude!!! Bellaaaaaa!!!
Matt Fig
Matt Fig el 14 de Abr. de 2011
What have you done so far to solve your problem? Show your work and ask a specific MATLAB question, then you will get help.
NONE NONE
NONE NONE el 15 de Abr. de 2011
ITS a MATLAB QUESTION DUDE!!!
Sean de Wolski
Sean de Wolski el 15 de Abr. de 2011
I don't know. It sounds more theoretical to me (citation: Matt's answer)
Walter Roberson
Walter Roberson el 15 de Abr. de 2011
NONE NONE: you did not write a question, you wrote imperative statements, also known as "commands". Imperative statements are similar to, "Take out the garbage", "Cut your hair", and "Give me the answer to my homework question." Questions ask something, and look like, "What is the air-speed velocity of an unladen swallow?", or "Could you help me find documentation on how to add numbers without using a loop?", or "Could I get you another beer?"
Sean de Wolski
Sean de Wolski el 15 de Abr. de 2011
Is that an African or European swallow? And, how many beers have you gotten for the swallow?
Walter Roberson
Walter Roberson el 15 de Abr. de 2011
Swallows prefer cider.
http://www.aeppeltreow.com/images/Barn%20Swallow%20Cider%20v1%20-%20working.jpg
Matt Tearle
Matt Tearle el 15 de Abr. de 2011
How could a swallow carry a beer? (Note: it's not a question of where he grips it -- it's a simple question of weight ratios)
Matt Fig
Matt Fig el 15 de Abr. de 2011
@Matt,
http://bottlecollecting.blogspot.com/
Walter Roberson
Walter Roberson el 15 de Abr. de 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/

Iniciar sesión para comentar.

Respuestas (4)

Matt Tearle
Matt Tearle el 14 de Abr. de 2011

3 votos

Why bother? The answer is -Inf. Your teacher needs to write more precise questions.

4 comentarios

Walter Roberson
Walter Roberson el 15 de Abr. de 2011
Matt, infinity is neither even nor odd, so the most you can do is talk about the _limit_ of the answer rather than the answer itself.
Matt Tearle
Matt Tearle el 15 de Abr. de 2011
But if you add up all the even negative integers (up to -realmax), in MATLAB you'll get a -Inf result. And because infinity isn't a number, the question itself is, by definition, a limit problem (which will result in -infinity, so MATLAB is right! W00t!)
Walter Roberson
Walter Roberson el 16 de Abr. de 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 el 18 de Abr. de 2011
Hah. I just realized that, in my mind, a:dx:b goes "up to b", even if dx < 0. Stupid semantics.

Iniciar sesión para comentar.

Paulo Silva
Paulo Silva el 14 de Abr. de 2011

2 votos

)05:2:2(mus

2 comentarios

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

Iniciar sesión para comentar.

Jan
Jan el 15 de Abr. de 2011

1 voto

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 el 14 de Abr. de 2011

0 votos

Okay, I wrote it. Can I have a beer now?

5 comentarios

Oleg Komarov
Oleg Komarov el 14 de Abr. de 2011
I want the pointsssssssssss to increase the distance Sean :)...
Matt Tearle
Matt Tearle el 14 de Abr. de 2011
Yes, but you probably have to buy it yourself.
Sean de Wolski
Sean de Wolski el 14 de Abr. de 2011
Oleg, you take the points I take the beer?
Sean de Wolski
Sean de Wolski el 14 de Abr. de 2011
Matt, I thought that was one of the conditions of solving a doit4me?
Oleg Komarov
Oleg Komarov el 14 de Abr. de 2011
Doh...

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 14 de Abr. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by