45 lines
781 B
C
45 lines
781 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
//utiliser la recu ?
|
|
//possible mais avec fct aux
|
|
//malloc dans my_factor puis appelle aux (poineur, n)
|
|
int *my_factor(int n){
|
|
|
|
if (n <= 0) return NULL;
|
|
//if (n == 1) return 1;
|
|
|
|
int cnt = 0;
|
|
int tmp = n;
|
|
int div = 2;
|
|
|
|
while(tmp > 1){
|
|
if (tmp % div == 0){
|
|
cnt ++;
|
|
tmp = tmp /div;
|
|
}
|
|
else div ++;
|
|
}
|
|
|
|
int *rslt = malloc((cnt + 1)* sizeof(int));
|
|
if(rslt == NULL) return NULL;
|
|
|
|
int index = 0;
|
|
int *kebab = rslt;
|
|
tmp = n;
|
|
div = 2;
|
|
|
|
while (tmp > 1) {
|
|
if (tmp % div == 0){
|
|
*(kebab + index) = div;
|
|
index ++;
|
|
tmp = tmp / div;
|
|
}
|
|
else div ++;
|
|
}
|
|
|
|
*kebab = 0;
|
|
return rslt;
|
|
|
|
}
|
|
|