Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Finding sum of all digits from 1 to 1 million.

by runrig (Abbot)
on Jan 24, 2002 at 00:38 UTC ( [id://141017]=note: print w/replies, xml ) Need Help??


in reply to Finding sum of all digits from 1 to 1 million.

..FROM ONE TO ONE MILLION INCLUSIVE

Your program has:

for ($i=0; $i<1e6; $i++) { ...
You're missing 1,000,000 and so are off by one.
Here's another way (which is still the long way, BTW):
my $total; for (1..1_000_000) { $total += $_ for split ""; } print "$total\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://141017]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-19 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found