
Factoring is simple if you utilize the 'mod' operator to see if a number is divisible by another. The 'mod' operator results in the remainder when its left side is divided by its right side. Thus, if the remainder is 0, the left number is divisible by the right number.
This makes a very simple, straightforward single-loop program like mine:
#include <stdio.h>
main() {
FILE *fin = fopen ("factor.in", "r");
FILE *fout = fopen ("factor.out", "w");
int n, sum=0, i;
fscanf (fin, "%d", &n);
for (i = 1; i < n; i++) {
if (n%i == 0) sum += i;
}
fprintf (fout, "%d\n", sum);
exit (0);
}