DEV/BUT1/DEV1.1/CM2_2/CM2/exo3.c

39 lines
718 B
C
Raw Normal View History

2024-02-01 13:55:03 +01:00
#include <stdio.h>
#include <stdlib.h>
int* suite(int entier){
int i = 0, result = entier, nombre_operation;
int* tab;
for (nombre_operation = 0; (result % 2) != 0; i++){
result = result / 2;
}
tab = (int*) malloc(nombre_operation * sizeof(int));
tab[0] = entier;
for (i = 1; (entier % 2) != 0; i++){
entier = entier / 2;
tab[i] = entier;
printf("%d", tab[i]);
}
return tab;
}
int main(void){
int i;
int* tab1 = suite(5);
int* tab2 = suite(6);
int* tab3 = suite(7);
for(i=0;i<10;i++){
printf("%d\n",tab1[i]);
}
free(tab1);
free(tab2);
free(tab3);
return EXIT_SUCCESS;
}