Commit fb7775ab authored by xingqiao's avatar xingqiao
Browse files

helloworld basic code files

parent ef521bac
#include <stdio.h>
#include <math.h>
int main(void) {
printf("Enter a number to factorize:\n");
......@@ -8,6 +9,23 @@ int main(void) {
fprintf(stderr, "Invalid input. Please enter a number.\n");
return 1;
}
printf("Prime factors:\n");
int factor = 2;
int upper = sqrt(number);
while (number != 1) {
upper = sqrt(number);
if (factor > upper) {
printf("%d\n", number);
return 0;
}
if (number % factor == 0) {
printf("%d\n",factor);
number /= factor;
}else {
factor += 1;
}
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment