Ajout TPS + Entrainements

This commit is contained in:
Simoes Lukas
2024-12-10 12:52:05 +01:00
parent 6f3e79de9d
commit f7764aa296
20 changed files with 577 additions and 30 deletions

View File

@@ -2,31 +2,34 @@
# include <stdlib.h>
int main(void) {
int taille_tab;
int taille_tab = 0;
double entree;
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));
for (i = 0; i != taille_tab; i++) {
printf("Entrez le %de réel : ", i + 1);
scanf("%lf", &tab[i]);
while( entree != (double) 'q') {
taille_tab++;
tab = (double*) realloc(tab, sizeof(double));
tab_compteurs = (int*) realloc(tab_compteurs, sizeof(int));
printf("Entrez le %de réel : ", taille_tab);
scanf("%lf", &entree);
getchar();
tab[taille_tab] = entree;
tab_compteurs[taille_tab] = 0;
}
for (i = 0; i != (taille_tab - 1); i++) {
for (j = i; j != taille_tab; j++) {
if (tab[i] == tab[j]) {
tab[j] = 0.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[i] != 0.0) {
printf("%.3f ", tab[i]);
for (i = 0; i!=taille_tab; i++) {
if (tab_compteurs[i] == 1) {
printf("| %lf ", tab[i]);
}
}
putchar('\n');