Re: ASSIGNMENT



On April 24, 2009 09:59, in comp.lang.c, Mark Bluemel
(mark_bluemel@xxxxxxxxx) wrote:

Lew Pitcher wrote:
On April 24, 2009 09:46, in comp.lang.c, Mark Bluemel
(mark_bluemel@xxxxxxxxx) wrote:

Lew Pitcher wrote:
On April 24, 2009 08:56, in comp.lang.c, azom47@xxxxxxxxx
(azom47@xxxxxxxxx) wrote:

COULD YOU PLEASE SOLVE THE FOLLOWING QUESTION.

WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM
0 TO 20?
...
We are not a "homework help line", but if you post what you've done so
far, we can help you by making suggestions as to how to fix what you've
done.

/I/ will go further than that, though. I will tell you how to write the
program you've asked us about.

First off, don't even think of C.

Think about mathematics. What have you learnt about sums of series (have
you learnt anything about them)? Can you apply this to the problem in
hand?

Hint: If it were all the even numbers from 2 to 10,000,000 you wouldn't
even consider doing individual addition would you?

Of course.

OTOH, an obvious simple homework problem, and an OP who cant solve it,
points to a "beginners" course in C. Homework is given for a reason, and
a C-language homework problem of such a simple nature isn't likely meant
to teach how to apply lateral thinking to mathematical problems. Instead,
it is likely to be re-enforcing the basics of the C language.

So, a lateral reinterpretation of the mathematics could be the solution
to the problem as stated. But then again, so could a simple for() loop
which constructs the solution using simple arithmetic. And the for() loop
is more likely to be what the homework is all about, don't you think?

Fair comment. Could also be done as an exercise in recursive functions.

Yes. But if the OP can't solve the problem with a for() loop, then
he's /really/ in no shape to understand recursion ;-)

Depending on his tutor, he could get bonus points for finding a "better"
solution.

IIRC, there's a precedent for that.

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------


.



Relevant Pages

  • Re: ASSIGNMENT
    ... WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM ... C-language homework problem of such a simple nature isn't likely meant to ... a lateral reinterpretation of the mathematics could be the solution to ... And the forloop is more ...
    (comp.lang.c)
  • Re: ASSIGNMENT
    ... WRITE A PROGRAM IN C THAT WILL CALCULATE THE SUM OF EVEN NUMBERS FROM ... C-language homework problem of such a simple nature isn't likely meant to ... a lateral reinterpretation of the mathematics could be the solution to ... And the forloop is more ...
    (comp.lang.c)
  • Infinite series problem
    ... This was posted yesterday on a web site I frequent; it was a homework problem ... I decided to multiply out the i terms and get a sum in i^2 and another in i. ... The first term appears to sum to -1/3, the second to 2/3, and I got the product ... (I just have to remember to multiply successive series by successive odd ...
    (sci.math)
  • Re: Binary search in Matlab
    ... > exist a way to make this without loop. ... Since a binary search is inherently an iterative ... homework problem. ... The best material model of a cat is another, or preferably the same, cat. ...
    (comp.soft-sys.matlab)
  • Re: A couple problems involving structures and loops
    ... Really I just need some help writing the loop, as it's the aspect of this language thus far that I have the weakest grasp of. ... I'd probably first call fieldnames() and then I'd loop over all field ... For homework problem #2, you'll find sortand sortrowsuseful, ...
    (comp.soft-sys.matlab)