You may do it with recursion. if u have numbers in an array
int sum=0;
int sum(int num)
{
sum+=num;
}
Alternatively, if u are accepting numbers from user, u can call this
function along with the input statement in which u might need a loop for
input statement at least.
Nawaid.
Sent from my iPhone
On Dec 22, 2011, at 17:47, Luke Pebody <[email protected]> wrote:
The point was to find the "best optimized" solution. I was optimizing
according to the readability and understandability metrics. This is not
something I always do.
On 21 Dec 2011 20:07, "Jérémie Marguerie" <[email protected]> wrote:
> 2011/12/21 Luke Pebody <[email protected]>:
> > For sheer expressiveness reasons, I would choose something like Python's
> >
> >> print sum([int(char) for char in "142857"])
> > 27
>
> But the point gere is to find a fast algorithm, you need a low level
> language to do so :)
>
> Thinkinf of that, if we consider the memory block containing the
> string to be 4-bytes aligned, we can process 4 integers in the loop
> and avoid a jump between each byte and only jump each four bytes.
>
> --
> Jérémie MARGUERIE
> Étudiant à l'EPITA, ing2
> "Many snake oil algorithms claim unbreakability by claiming to be a OTP.
> Pseudo-OTPs give pseudo-security" -- Peter Gutmann
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-code?hl=en.
>
> --
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.