Factor of array digit

This is my code for the above problem can someone tell me the right code with the right explaination