wer0ckz Posted March 22, 2011 Share Posted March 22, 2011 Hi guys. help please. How to code few lines for small program that calculates the sum of the first 540 natural numbers. Start numbering from 0. Is there a url tutorial about my issue? Thanks Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 22, 2011 Share Posted March 22, 2011 What do you mean by "natural numbers"? Whole numbers like 1,2,3, ... etc? Ken Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 22, 2011 Share Posted March 22, 2011 http://www.9math.com/book/sum-first-n-natural-numbers function sumOfNaturalNumbers($maxNum) { return ($maxNum * ($maxNum + 1)) / 2; } $answer = sumOfNaturalNumbers(540); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.