Integer Factorization in C Language
Higher category : C Language
a. GitHub
#include <stdio.h>
#include <stdlib.h>
/* This source is for integer factorization */
int main(int argc, char *argv[]) {
int n;
scanf("%d", &n);
int i = 2; // "1" is not prime, so starting with "2" is reasonable
while(1){
if(n == 1) break;
if(n % i == 0){
printf("%d ", i);
n = n / i;
i--; // primes can divide the given number many times
}
i++;
}
return 0;
}
Input: 2016.02.16 13:15