Sum and average even numbers

조회 수: 10 (최근 30일)
NONE NONE
NONE NONE 2011년 4월 14일
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
Matt Fig
Matt Fig 2011년 4월 15일
@Matt,
http://bottlecollecting.blogspot.com/
Walter Roberson
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
Matt Tearle 2011년 4월 14일
Why bother? The answer is -Inf. Your teacher needs to write more precise questions.
  댓글 수: 4
Walter Roberson
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
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.

댓글을 달려면 로그인하십시오.


Paulo Silva
Paulo Silva 2011년 4월 14일
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2011년 4월 14일
That's a pretty sweet emoticon. A cyclops with a button down suit?
Paulo Silva
Paulo Silva 2011년 4월 14일
lol that's funny, it does look weird and cool at the same time :)

댓글을 달려면 로그인하십시오.


Jan
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?

Sean de Wolski
Sean de Wolski 2011년 4월 14일
Okay, I wrote it. Can I have a beer now?
  댓글 수: 5
Sean de Wolski
Sean de Wolski 2011년 4월 14일
Matt, I thought that was one of the conditions of solving a doit4me?
Oleg Komarov
Oleg Komarov 2011년 4월 14일
Doh...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by