Assume there is a list:
List1={a,b,c,d};
Then I want to get these calculation:
Output1= a
Output2= a*b
Output3= a*b*c
Output4= a*b*c*d
Could you please help me with this problem? Thank you in advance.
Assume there is a list:
List1={a,b,c,d};
Then I want to get these calculation:
Output1= a
Output2= a*b
Output3= a*b*c
Output4= a*b*c*d
Could you please help me with this problem? Thank you in advance.
list1 = {a, b, c, d};
Rest[FoldList[Times, 1, list1]]
Scan[Print, %]
a
a b
a b c
a b c d
You can also use Accumulate
list1 = {a, b, c, d};
Times @@@ Accumulate[list1]
(* or Accumulate[list1] /. Plus -> Times *)
{a, a b, a b c, a b c d}
... or ReplaceList:
ReplaceList[list1, {x__, ___} :> Times[x]]
{a, a b, a b c, a b c d}
My version of Bob Hanlon's comment solution:
list1 = {a, b, c, d};
FoldList[Times, list1]
% // Column
{a, a b, a b c, a b c d}a a b a b c a b c d
Reference: Shorter syntax for Fold and FoldList?