
The only trick on this task is to iterate through all the possible factors and print those that exactly divide the integer of question. It is important to be able to find multiple copies of the same divisor, so a second loop is necessary.
#include <stdio.h>
main () {
FILE *fin = fopen ("pfact.in", "r");
FILE *fout = fopen ("pfact.out", "w");
int n, i;
fscanf (fin, "%d", &n);
for (i = 2; i <= n; i++)
while (n % i == 0) {
fprintf (fout, "%d\n", i);
n /= i;
}
exit (0);
}