Ajout TPS + Entrainements
This commit is contained in:
39
DEV1.1/Entrainements/controle_machine_2_A/suite.c
Normal file
39
DEV1.1/Entrainements/controle_machine_2_A/suite.c
Normal file
@@ -0,0 +1,39 @@
|
||||
# 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;
|
||||
}
|
Reference in New Issue
Block a user