Given A is a 10 × 30 matrix, B is a 30 × 5 matrix
IIRC, then AB is valid because 30 equals 30; results in a 10 X 5 matrix answer.
But, BA is not valid because 5 does not equal 10.
The assignment doesn't describe the input format, though, and the OP seems to have interpreted it as being a single integer. In which case we would be talking about square matrices.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law