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:

screen-shot-2016-09-08-at-11-15-44-am

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

Advertisements
Sum Nums

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s