How to write this program?

How to solve this? Any help would be appreciated :S

http://img684.imageshack.us/img684/5099/xxxxxxl.jpg
Hint1: Start at the base row of any triangle of size N. There are N cans in that row (obviously). For each successive row on the way to the apex (top can) there are N-1 cans. Hmmm, sounds like a sequence: N, N-1, N-2, N-3... (hint2: when you reach N-N you get a zero (obviously).

So... For each 2D level of cans it's pretty easy to calculate the total number required.
5, for example = 5+4+3+2+1 = 15 cans.

Now you have to implement that algorithm in C++. Try starting out with some simple pseudo-code and move on from there...
Topic archived. No new replies allowed.