#include<stdio.h> #include<stdlib.h> /*---------------------PROTOTYPE---------------------------------------------*/ int nombreSingletonTableau(double tableau[], int tailleTableau); void valeurSingleton(double tableau[], double tableauFinal[], int tailleTableau, int tailleTableauFinal); void afficheTableau(double tableau[], int tailleTableau); /*-------------------------------MAIN----------------------------------------------------*/ int main(void){ double *tableau=NULL, *tableauFinal=NULL; int compteur=0, reponse=0, compteurBis=0, tailleTableauFinal; printf("Veuillez entrez le nombre de réel que vous allez entrez : "); scanf("%d", &reponse); tableau=(double*) malloc(reponse*sizeof(double)); for(compteur=0;compteur<reponse;compteur++){ printf("Veuillez entrez le reel %d/%d\n",compteur+1, reponse); scanf("%lf", &tableau[compteur]); } tailleTableauFinal = nombreSingletonTableau(tableau,reponse); printf("Il y'a %d Singleton\n\nCes derniers sont : \n\n",tailleTableauFinal); tableauFinal=malloc(tailleTableauFinal*sizeof(double)); valeurSingleton(tableau, tableauFinal, reponse, tailleTableauFinal); afficheTableau(tableauFinal, tailleTableauFinal); free(tableau); free(tableauFinal); printf("\nAu revoir\n"); return EXIT_SUCCESS; } /*---------------------------------------------------FONCTIONS---------------------------------------------------------------------*/ int nombreSingletonTableau(double tableau[], int tailleTableau){ int compteur=0, compteurBis=0, compteurCase=0 , nombreSingleton=0; for(compteur=0;compteur<tailleTableau;compteur++){ compteurCase=1; /*1 represente la case en question elle meme */ for(compteurBis=0;compteurBis<tailleTableau;compteurBis++){ if(tableau[compteur]!=tableau[compteurBis] && compteur!=compteurBis){ compteurCase++; } } if(compteurCase == tailleTableau){ nombreSingleton++; } } return nombreSingleton; } void valeurSingleton(double tableau[], double tableauFinal[], int tailleTableau, int tailleTableauFinal ){ int compteur=0, compteurBis=0, compteurCase=0 , caseTableauFinal=0; for(compteur=0;compteur<tailleTableau;compteur++){ compteurCase=1; /*1 represente la case en question elle meme */ for(compteurBis=0;compteurBis<tailleTableau;compteurBis++){ if(tableau[compteur]!=tableau[compteurBis] && compteur!=compteurBis){ compteurCase++; } } if(compteurCase == tailleTableau){ tableauFinal[caseTableauFinal++]=tableau[compteur]; } } } void afficheTableau(double tableau[], int tailleTableau){ int compteur=0; for(compteur=0;compteur<tailleTableau;compteur++){ printf("%lf ", tableau[compteur]); } printf("\n"); }