Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there any code built in to add the numbers in a list sequentially? For example, lets say I have a list B. B has 6 numbers like below.

B={0,6,5,4,3,2}

I want to produce a new list C. C will add the first two numbers in the list, so 0+6 = 6. That will be put into the new list C. Then the next term in the list C will be 0+6+5 = 11. And then 0+6+5+4 = 15, and so on. The result of the new list C will be as below.

C={6,11,15,18,20}

Any help is appreciated. Thanks.

share|improve this question

closed as off-topic by rasher, Öskå, Sjoerd C. de Vries, m_goldberg, Michael E2 Jun 16 at 21:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – rasher, Öskå, Sjoerd C. de Vries, m_goldberg, Michael E2
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Why did you tag this with webmathematica? There's no mention of webMathematica in the question. –  Szabolcs Jun 16 at 19:40
1  
Keep in mind that C is a built-in symbol. –  Kuba Jun 16 at 19:43

1 Answer 1

up vote 2 down vote accepted

Use Accumulate.

Accumulate[{0, 6, 5, 4, 3, 2}]

(* {0, 6, 11, 15, 18, 20} *)
share|improve this answer
1  
To get the requested result you need to add Rest: Accumulate[{0, 6, 5, 4, 3, 2}]//Rest or alternatively Accumulate[{0, 6, 5, 4, 3, 2} // Rest] –  Bob Hanlon Jun 16 at 19:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.