Re: Unknown number of inputs



f2prateek wrote On 01/30/07 01:14,:
I want to make a program to print the average of the numbers entered
by the user,but how do i accept the numbers from the user,if the
number of numbers enetred by him or not known to me??

Various people have suggested ways to store a bunch
of numbers in an array or ArrayList or Vector or whatever.

That's silly.

I'm going to read you a bunch of numbers -- you don't
know exactly how many -- and at some point I'll ask you to
tell me the average of the numbers you've been read. Can
you do the job without keeping a record of each individual
number?

Hint: Consider an even more complicated problem (as is
sometimes the case, a more general problem may be simpler
than a specific problem, and may offer a clue to solving
it.) After you've reported an average, I'll read you some
more numbers and then ask for the average of all the numbers
to date. And then more, and then more -- or, to look at it
another way, I'll read you a bunch of numbers and interrupt
myself every now and then to ask for the average thus far.
Can you do the job without recording every individual number?

--
Eric.Sosman@xxxxxxx
.



Relevant Pages

  • Re: proposed name for Saturnian moon S/2005 S1
    ... and probably everyone else with a clue. ... >astronomical bodies are currently named by a bunch of transvestite and ...
    (sci.space.history)
  • Re: OT- Thank you God . . .
    ... to keep this moose in the headlights why should we contradict them? ... Is it that surprising that a bunch of dumb shits who didn't have a clue ...
    (rec.gambling.poker)
  • Re: [Info-vax] IPSec - Dear God in heaven NO!
    ... You'll have to quote a bit more liberally, or at least give me some clue as ... suckle their exorbitant salaries at the VMS license-payer teat, ... The snake - coiled, ... appeared to be a bunch of IT professionals not a bunch of ...
    (comp.os.vms)
  • Re: Alan Keyes
    ... infiltrated protest groups and intentionally sparked social unrest? ... They're all a bunch of liberal commie bastards. ... where a clue might be. ...
    (rec.gambling.poker)
  • Re: Symmetric matrices only!
    ... nonsymmetric matrices. ... I've got a bunch of them to solve. ... solving a symmetric matrix is another science than a asymmetric one. ... In some areas a 10_000 x 10_000 matrix is a toy one, for testing small examples (e.g. solving a physics equation on a 100x100 grid)... ...
    (comp.lang.ada)