I am presuming that you are a beginner. First please put the above code by formatting it properly, ( Here’s the link) .
Now even though your logic is correct, you are not storing the factors anywhere hence you won’t be able to print them.
You need to use another data structure to store those factors. An array, a vector or something like that.
Note: You above logic has O(n) time complexity, there is a faster way to do this in
O( \sqrt n)