-------------------------------------------------------------------------------------------------
Programa
-------------------------------------------------------------------------------------------------
/* El programa tira los dados de forma independiente 5000000 veces se mostrara el resultado en forma de tabla*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int sorteo1(void);
int sorteo2(void);
main()
{
int i, j, k=1, l, o, sum;
int a[13]={0};
int freq[6][6]={0};
float Probabilidad[13];
srand(time(NULL));
while(k<=5000000){
i = sorteo1();
j = sorteo2();
/* printf("%d, %d\n", i, j); */
sum=i+j;
if(i==1){
switch(j){
case 1 : freq[1][1]= freq[1][1] + 1;
break;
case 2 : freq[1][2] = freq[1][2] + 1;
break;
case 3 : freq[1][3] = freq[1][3] + 1;
break;
case 4 : freq[1][4] = freq[1][4] + 1;
break;
case 5 : freq[1][5] = freq[1][5] + 1;
break;
case 6 : freq[1][6] = freq[1][6] + 1;
break;
default : ;
break;
}
}else if(i==2){
switch(j){
case 1 : freq[2][1] = freq[2][1] + 1;
break;
case 2 : freq[2][2] = freq[2][2] + 1;
break;
case 3 : freq[2][3] = freq[2][3] + 1;
break;
case 4 : freq[2][4] = freq[2][4] + 1;
break;
case 5 : freq[2][5] = freq[2][5] + 1;
break;
case 6 : freq[2][6] = freq[2][6] + 1;
break;
default : ;
break;
}
}else if(i==3){
switch(j){
case 1 : freq[3][1] = freq[3][1] + 1;
break;
case 2 : freq[3][2] = freq[3][2] + 1;
break;
case 3 : freq[3][3] = freq[3][3] + 1;
break;
case 4 : freq[3][4] = freq[3][4] + 1;
break;
case 5 : freq[3][5] = freq[3][5] + 1;
break;
case 6 : freq[3][6] = freq[3][6] + 1;
break;
default : ;
break;
}
}else if(i==4){
switch(j){
case 1 : freq[4][1] = freq[4][1] + 1;
break;
case 2 : freq[4][2] = freq[4][2] + 1;
break;
case 3 : freq[4][3] = freq[4][3] + 1;
break;
case 4 : freq[4][4] = freq[4][4] + 1;
break;
case 5 : freq[4][5] = freq[4][5] + 1;
break;
case 6 : freq[4][6] = freq[4][6] + 1;
break;
default : ;
break;
}
}else if(i==5){
switch(j){
case 1 : freq[5][1] = freq[5][1] + 1;
break;
case 2 : freq[5][2] = freq[5][2] + 1;
break;
case 3 : freq[5][3] = freq[5][3] + 1;
break;
case 4 : freq[5][4] = freq[5][4] + 1;
break;
case 5 : freq[5][5] = freq[5][5] + 1;
break;
case 6 : freq[5][6] = freq[5][6] + 1;
break;
default : ;
break;
}
}else if(i==6){
switch(j){
case 1 : freq[6][1] = freq[6][1] + 1;
break;
case 2 : freq[6][2] = freq[6][2] + 1;
break;
case 3 : freq[6][3] = freq[6][3] + 1;
break;
case 4 : freq[6][4] = freq[6][4] + 1;
break;
case 5 : freq[6][5] = freq[6][5] + 1;
break;
case 6 : freq[6][6] = freq[6][6] + 1;
break;
default : ;
break;
}
}else{};
switch(sum){
case 2 : a[2]++;
break;
case 3 : a[3]++;
break;
case 4 : a[4]++;
break;
case 5 : a[5]++;
break;
case 6 : a[6]++;
break;
case 7 : a[7]++;
break;
case 8 : a[8]++;
break;
case 9 : a[9]++;
break;
case 10 : a[10]++;
break;
case 11 : a[11]++;
break;
case 12 : a[12]++;
break;
default : ;
break;
}
k = k + 1;
}
printf("Los resultados son\n");
printf("\t [j=1]\t [j=2]\t [j=3]\t [j=4]\t [j=5]\t [j=6]\n");
for(l=1; l<=6; l++){
printf("[i=%d]\t %d\t %d\t %d\t %d\t %d\t %d\n", l, freq[l][1], freq[l][2], freq[l][3], freq[l][4], freq[l][5], freq[l][6]);
};
for (o=2; o<=12; o++){
Probabilidad
- = (float)a
- /(float)5000000;
printf("el valor\t%d \tse obtuvo \t%d veces\t Probabilidad : %4.2f\n", o, a
- , Probabilidad
- );
return 0;
}
int sorteo1(void)
{
int m;
m= (1+(rand()%6));
/*printf("%d\n",i);*/
return m;
}
int sorteo2(void)
{
int n;
n = ((rand()%6)+1);
/*printf("%d\n",j);*/
return n;
}
------------------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Resultados
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Los resultados son
[j=1] [j=2] [j=3] [j=4] [j=5] [j=6]
[i=1] 139028 138463 138908 138484 138397 139588
[i=2] 138629 138542 138601 138962 138716 138274
[i=3] 139068 139052 138902 138533 138982 139117
[i=4] 138994 138669 138774 139443 139414 139231
[i=5] 138966 138549 139167 139264 138653 138762
[i=6] 139191 278498 415715 555765 694127 832237
el valor 2 se obtuvo 278498 veces Probabilidad : 0.06
el valor 3 se obtuvo 415715 veces Probabilidad : 0.08
el valor 4 se obtuvo 555765 veces Probabilidad : 0.11
el valor 5 se obtuvo 694127 veces Probabilidad : 0.14
el valor 6 se obtuvo 832237 veces Probabilidad : 0.17
el valor 7 se obtuvo 833351 veces Probabilidad : 0.17
el valor 8 se obtuvo 695336 veces Probabilidad : 0.14
el valor 9 se obtuvo 556418 veces Probabilidad : 0.11
el valor 10 se obtuvo 417131 veces Probabilidad : 0.08
el valor 11 se obtuvo 277758 veces Probabilidad : 0.06
el valor 12 se obtuvo 138341 veces Probabilidad : 0.03