Wednesday, September 28, 2011

Project Euler - Problem Six

These exercises are really helping my programming. This one took about fifty-five seconds of planning a a few minutes to write up. It's a bit spaced out to do in one screenshot, so I'll space it out a bit.

The code is fairly simple for this one. Here's the problem:
Now, I see two different functions there, but I don't know about you. I'm going to go ahead and declare them like this:
The functions themselves are very straightforward and didn't take much thinking through.
Add_squares adds the squares of all the numbers:
Square_sum adds all the numbers and then squares it:
Finally, I wrapped them all up in a nice main function:
Also....you'll notice that I got excited and forgot to change my cout statement....soooo...

So, that's it. Easier than pi!

No comments:

Post a Comment