1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| #include <stdio.h>
#include <stdlib.h>
#include <time.h>
char* lancer_des(char *des[], int numero_des){
srand(numero_des);
*des[numero_des] = rand() % 5 + 1;/*Ainsi, le chiffre sera entre 1 et 6.*/
printf("des %d: %d \n",numero_des, *des[numero_des]);
return (char *)des[numero_des];
}
//-----------------------------------------------------------------------------
char* trie(char *tableau[]){
int i;
int t;
int j;
for(i=1; i<7; i++){
for(j=7; j>1; j--){
if (*tableau[j-1]>*tableau[j]){
t=*tableau[j-1];
*tableau[j-1]=*tableau[j];
*tableau[j]=t;
}
}
}
return *tableau;}
//------------------------------------------------------------------------------
int* partie_superieure(char *occurence[], int n){
int *compte;
int i;
int j=0;
compte=malloc(sizeof(int)*10);
for(i=0; i<n; i++){
*compte+=*(occurence+1);
}
if(*compte>=63){*compte+=35;}
printf("compte: %d ", *compte);
return *compte; }
//------------------------------------------------------------------------------
int main(void){
srand (time(NULL));
char *des[7];
int i;
int j;
int t=0;
char *occurence[7];
int *compte;
int cpt=0;
int only=0;
int choix;
for(i=1; i<7; i++){
des[i]=malloc(sizeof(char));
}
for(i=1; i<7; i++){
*(des+i)=lancer_des(des,i);}
//Ainsi, la variable ne sera pas détruite à la fin de la fonction.
compte=malloc(sizeof(int)*10);
for(i=1; i<7; i++){
occurence[i]=malloc(sizeof(char));
occurence[i]=0;
}
trie(des);
for (i=1; i<7; i++){
if(*des[i]==*des[i+1]){occurence[*des[i]]+=1;}
}
for(i=1; i<7; i++){
if (occurence[i]>0){occurence[i]+=1;}
}
for(j=1; j<7; j++){
if(cpt>2){occurence[i-3]+=1; only=i-3;}
cpt=0;
for(i=1; i<7; i++){
if(*des[i]!=*des[j]){cpt++;}else{cpt=0;}
}
}
occurence[only]=1;
for(i=1; i<7; i++){
printf("le nombre %d a ete repete %d fois. \n",i, occurence[i]);
}
printf("1. Compter les 1 \n");
scanf("%d",&choix);
switch(choix){
case 1: partie_superieure(occurence[1],1); break;}
return 0;} |
Partager