39 lines
600 B
C
39 lines
600 B
C
|
# include <stdio.h>
|
||
|
# include <stdlib.h>
|
||
|
|
||
|
|
||
|
int* suite(int n) {
|
||
|
int* p = NULL;
|
||
|
int compteur = 0;
|
||
|
p = (int*) malloc(sizeof(int));
|
||
|
if (p) {
|
||
|
p[0] = n;
|
||
|
while (!n%2) {
|
||
|
compteur++;
|
||
|
p = (int*) realloc(p, sizeof(int));
|
||
|
n = n/2;
|
||
|
p[compteur] = n;
|
||
|
}
|
||
|
return p;
|
||
|
}
|
||
|
else {
|
||
|
printf("Espace mémoire insuffisant.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void afficher_tableau(int* t) {
|
||
|
int i;
|
||
|
size_t max = *(&t + 1) - t;
|
||
|
printf("%lu", max);
|
||
|
for (i = 0; i != max ; i++) {
|
||
|
printf("| %d", t[i]);
|
||
|
}
|
||
|
printf("\n");
|
||
|
}
|
||
|
|
||
|
|
||
|
int main(void) {
|
||
|
int tab[5] = {2, 5, 8, 9, 1};
|
||
|
afficher_tableau(tab);
|
||
|
return EXIT_SUCCESS;
|
||
|
}
|