Scrivere un programma che simuli il lancio di due dadi per 36.00 volte sommi i due risultati, visualizzate i risultati in un formato tabulare.
[ot]
[/ot]
ecco il mio output:
acifistamg:
[ot]
Codice:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define SIZE 13
int main()
{
int frequenze[SIZE] = {0};
int x;
int y;
int k;
int somma;
int f;
srand( time( NULL ) );
for(x=1;x <= 36000; x++) {
y = 1 + ( rand() % 6 );
k = 1 + ( rand() % 6 );
somma = k + y;
++frequenze[somma];
}
printf( "%s%17s\n", "Rating", "Frequency");
for(f=0;f<=12;f++)
printf("%6d%17d\n",f,frequenze[f]);
return 0;
}
ecco il mio output:
Codice:
edo1493@IGNAZIO:~$ ./vettori2
Rating Frequency
0 0
1 0
2 995
3 1946
4 2996
5 4044
6 5011
7 5918
8 4993
9 4186
10 3004
11 11
12 4