This repository has been archived on 2026-05-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2026-02-02 04:56:58 +01:00

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;
}