DEV/BUT1/CONTROLE/CM1/exo5.c

36 lines
804 B
C
Raw Normal View History

2024-02-01 13:55:03 +01:00
#include <stdlib.h>
#include <stdio.h>
int main() {
int des[5];
int j,i;
int maxOccurrences = 0, occurrences;
for (i=0;i<5;i++) {
printf("Jet n°%d : ", i + 1);
scanf("%d",&des[i]);
/*Vérifier que la valeur donner est entre 1 et 6*/
if(des[i]<1 || des[i]>6) {
printf("Veuillez entrer un entier entre 1 et 6.\n");
i--;
}
}
/*Compter les occurrences de chaque nombre*/
for(i=1;i<=6;i++){
occurrences = 0;
for(j=0;j<5;j++){
if(des[j] == i){
occurrences++;
}
}
if(occurrences > maxOccurrences){
maxOccurrences = occurrences;
}
}
printf("Occurrences maximum : %d\n", maxOccurrences);
return EXIT_SUCCESS;
}