I need to write a program, which shows the different combinations in which matrices can be multiplied.

The output should look like below :
When there are two matrices multiplied there is one combination
(XX)

When there are three matrices multiplied there are two combinations
(X(XX)) ((XX)X)

When there are four matrices multiplied there are five combinations
(X(X(XX))) ((X(XX))X) (X((XX)X)) (((XX)X)X) ((XX)(XX))

Can someone please help me with its logic?
Thank you,

think recursion.

I need to write a program, which shows the different combinations in which matrices can be multiplied.

The output should look like below :
When there are two matrices multiplied there is one combination
(XX)

When there are three matrices multiplied there are two combinations
(X(XX)) ((XX)X)

When there are four matrices multiplied there are five combinations
(X(X(XX))) ((X(XX))X) (X((XX)X)) (((XX)X)X) ((XX)(XX))

Can someone please help me with its logic?
Thank you,

Matrix multiplication is non-commutative operation, so X*Y!=Y*X.
So in your examples-
XY -> 2 combinations XY and YX
XYZ -> respectively 8 combinations.
But maybe it can be that your assignment ignores this fact for the sake of simplicity of assignment.

Matrix multiplication is non-commutative operation, so X*Y!=Y*X.
So in your examples-
XY -> 2 combinations XY and YX
XYZ -> respectively 8 combinations.
But maybe it can be that your assignment ignores this fact for the sake of simplicity of assignment.

As he seems to have only one matrix X that indeed seems to be the case.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.