You might also see if you can improve further upon that. Everything you find that input % factor == 0, you can get two factors. factor is the obvious one, but input / factor is also one.
Code:
#include <stdio.h>
#include <math.h>
int main(void)
{
long factor, endfact, input, factor2;
puts("Enter a number:");
scanf("%ld", &input);
puts("The factors are:");
printf("1\n%ld\n", input); // 1, input are always factors.
for(factor = 2, endfact = sqrt(input); factor <= endfact; ++factor)
{
if(input % factor == 0)
{
factor2 = input / factor;
printf("%ld\n", factor);
if(factor2 != factor)
printf("%ld\n", factor2);
}
}
return 0;
}
Uses less than sqrt(input) iterations, but the factors are out of order. (But it should be easy to order, if you know how many there are: they go smallest, biggest, 2nd-smallest, 2nd-biggest, etc, working towards a middle.)