Sum Nums

(First problem that I was able to solve without looking at the solution!)

Write a method that takes in an integer ‘num’ and returns the sum of all integers between zero and num, up to and including ‘num’.

Screen Shot 2016-08-11 at 12.10.35 PM

Basically, you want to write a simplified version of i + (i+1) + (i+2)…(i+num).

This doesn’t seem to take into account negative integers though?

Second time doing this problem, I got this:


Not as simple as my first one but it also works.

Sum Nums

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s