Current location - Training Enrollment Network - Mathematics courses - Mcdonald's mathematics
Mcdonald's mathematics
//the total number of times is x, and the mathematical expectation of x is found.

//The code is written. . . With 100000 random experiments, it is found that the mathematical expectation is stable at around 100000 times, at around 8.35438+0600.

//It can be considered that the mathematical expectation is 8.33 1600. Here is the code, followed by the answer.

# include & ltstdio.h & gt

# include & ltstring.h & gt

# include & lttime.h & gt

//This code is in C language. To become C++, just use the following two lines of code.

# include & ltiostream & gt

Use namespace std

int main()

{

int times[5];

Int mark;

Internal temperature;

Int count;

int I;

int sum

char c;

int k = 0;

int n = 100000;

Srand ((unsigned) (time(NULL))););

sum = 0;

Printf ("How many randomized trials have been conducted? \ n ");

n = 100000;

while( scanf("%d ",& ampn)& amp; & ampn & gt0 )

{

while( n -)

{

k++;

Flag^= national flag;

memset(times,0,sizeof(times));

And (flag! = 0x 1E)

{

temp = rand()% 4+ 1;

flag | =( 1 & lt; & lttemp);

times[temp]++;

}

Count = 0;

for(I = 1; I < = 4; i++)

{

Counts += multiplied by [I];

}

Sum+= count;

Printf ("The total number of trips to McDonald's during the collection of %d ABCD is X = %d\n", k, counts);

Printf ("mathematical expectation EX = %lf \n", k, (double)sum/k is obtained from the total number of times of collecting ABCD in the first %d times);

}

}

getchar();

Returns 0;

}

/*

How many randomized trials have been conducted? 100000

The total number of trips to McDonald's in the 1 ABCD set is X = 9.

The mathematical expectation EX = 9 is obtained from the total number of times ABCD is collected at 1.

The total number of trips to McDonald's in the second episode of ABCD is X = 8.

The mathematical expectation EX = 8.500000 is obtained from the total number of times of collecting ABCD in the previous two times.

.

.

.

.

.

.

The total number of trips to McDonald's in the 99989th ABCD collection is X = 6.

The mathematical expectation ex = 8.35438+0756 is obtained from the total number of times when ABCD was collected for the 99989th time.

The total number of trips to McDonald's in the 99990th ABCD collection is X = 4.

The mathematical expectation ex = 8.3 17 13 is derived from the total number of 99990 collections before ABCD.

The total number of trips to McDonald's in the 9999 1 collection of ABCD is X = 6.

The mathematical expectation ex = 8.399 1690 is obtained from the total number of times of collecting ABCD at 9999 1.

The total number of trips to McDonald's in 99992 ABCD collection is X = 5.

The mathematical expectation ex = 8.35438+0657 is obtained from the total number of times when ABCD was collected for the 99992nd time.

The total number of trips to McDonald's in 99993 ABCD set is X = 8.

The mathematical expectation ex = 8.35438+0653 is obtained from the total number of times when ABCD was collected for the 99993rd time.

The total number of trips to McDonald's in 99994 ABCD set is X = 6.

The mathematical expectation ex = 8.35438+0630 is obtained from the total number of times when ABCD was collected for the 99994th time.

The total number of trips to McDonald's in the 99995 ABCD collection is X = 6.

The mathematical expectation ex = 8.35438+0607 is obtained from the total number of times when ABCD was collected for the 99995th time.

The total number of trips to McDonald's in 99996 ABCD set is X = 7.

The mathematical expectation ex = 8.35438+0593 is obtained from the total number of times when ABCD was collected for the 99996th time.

The total number of trips to McDonald's in the 99997th ABCD collection is X = 9.

The mathematical expectation ex = 8.3 1600 is obtained from the total number of times when ABCD was collected for the 99997th time.

The total number of trips to McDonald's in 99998 ABCD collection is X = 9.

The mathematical expectation ex = 8.35438+0607 is obtained from the total number of ABCD collections in the first 99998 times.

The total number of trips to McDonald's in 99999 ABCD set is X = 15.

The mathematical expectation ex = 8.35438+0673 is obtained from the total number of ABCD collections in the first 99999 times.

The total number of trips to McDonald's in the100000th ABCD set is X = 13.

The mathematical expectation ex = 8.438+000000 is obtained from the total number of times of collecting ABCD10000th.

*/

//finally stabilized around 8.33 1600.

//It can be considered that the mathematical expectation is 8.33 1600.