2024-10-22 15:38:09 +02:00
|
|
|
------- TP19 : Allocation dynamique --------
|
|
|
|
|
2024-12-10 12:52:05 +01:00
|
|
|
1. # include <stdio.h>
|
|
|
|
# include <stdlib.h>
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
int taille_tab;
|
|
|
|
double* tab = (double*) malloc(3*sizeof(double));
|
|
|
|
int* tab_compteurs = (int*) malloc(sizeof(int));
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
printf("Combien de réels souhaitez-vous entrer ? ");
|
|
|
|
scanf("%d", &taille_tab);
|
|
|
|
getchar();
|
|
|
|
tab = (double*) realloc(tab, taille_tab*sizeof(double));
|
|
|
|
tab_compteurs = (int*) realloc(tab_compteurs, taille_tab*sizeof(int));
|
|
|
|
for (i = 0; i != taille_tab; i++) {
|
|
|
|
printf("Entrez le %de réel : ", i + 1);
|
|
|
|
scanf("%lf", &tab[i]);
|
|
|
|
getchar();
|
|
|
|
tab_compteurs[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i!=taille_tab; i++) {
|
|
|
|
for (j = 0; j != taille_tab; j++) {
|
|
|
|
if (tab[j] == tab[i]) {
|
|
|
|
tab_compteurs[i] += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i!=taille_tab; i++) {
|
|
|
|
if (tab_compteurs[i] == 1) {
|
|
|
|
printf("| %lf ", tab[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
2.
|
|
|
|
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <string.h>
|
|
|
|
|
|
|
|
char* inverse(const char* s) {
|
|
|
|
int taille_s = strlen(s);
|
|
|
|
char* s_inverse = (char*) malloc(sizeof(char));
|
|
|
|
int i;
|
|
|
|
int j = 0;
|
|
|
|
s_inverse = realloc(s_inverse, taille_s*sizeof(char));
|
|
|
|
for (i = taille_s-1; i>0; i--) {
|
|
|
|
s_inverse[j] = s[i];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
s_inverse[j] = s[0];
|
|
|
|
return s_inverse;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
int i;
|
|
|
|
for (i = 1; i != argc; i++){
|
|
|
|
if (strcmp(argv[i], inverse(argv[i])) == 0) {
|
|
|
|
printf(argv[i]);
|
|
|
|
printf(" est un palindrome.\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf(argv[i]);
|
|
|
|
printf(" n'est pas un palindrome.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
3.
|
2024-10-22 15:38:09 +02:00
|
|
|
|