Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #include <math.h>
- int factorcalc(int num, int div) {
- return (num/div);
- }
- int factorresto(int num, int div) {
- return (num%div);
- }
- bool isPrime(int num) {
- int i, flag = 1;
- for (i = 2; i <= round(sqrt(num)); i++) {
- if (num % i == 0) {
- flag = 0;
- break;
- }
- }
- if (flag == 1) {
- return true;
- }
- else {
- return false;
- }
- return 0;
- }
- int factor(int num, int array[]) {
- int savefactor[500];
- int e = 0;
- for (int t=0; t<500; t++) {
- while ((!isPrime(num)) && (factorresto(num, array[t]) == 0 )) {
- num = factorcalc(num, array[t]);
- savefactor[e] = array[t];
- printf("%d\n", savefactor[e]);
- e++;
- }
- }
- e++;
- if (num == 0) {
- e--;
- printf("Resultado-> %d", e);
- }else {
- printf("Resultado-> %d", e);
- }
- return 0;
- }
- int main() {
- int array[500] = {0};
- int countarray = 0;
- for (int u=2; u<500; u++) {
- if (isPrime(u)) {
- array[countarray] = u;
- countarray++;
- }
- }
- factor(42259155, array);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement