Wed Jan 23, 2013 1:35 am
void factor(int number, int n, int j) {
// Define integer
int i;
// 1 is not a prime number
if (n == 1) {
printf("1 is a unit\n");
return;
}
i = j;
while (i <= (int)(sqrt((double)n))) {
if (n % i == 0) {
// print a prime number i and continue search
fprintf(stdout, "%d\n", i);
factor(number, (int)(n / i), i);
return;
}
else {
i++;
}
}
// If you got this part means that n is prime number.
if (n == number)
printf("%d is prime\n", number);
else
printf("%d\n", n);
return;
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.