#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
srand(time(NULL));
int count = 0,a,b;
for(int i=0;i<10000;i++)
{
a = rand()%6+1;
b = rand()%6+1;
if(a+b == 7)
count++;
}
printf("%.2f%%",count/100.0);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int a,b,i;
int cnt = 0;
srand((unsigned int)time(NULL));
for (i=0;i<10000;i++)
{
a = rand()%6+1;
b = rand()%6+1;
if(a+b==7)
cnt++;
}
printf("概率:%d%%",100*cnt/10000);
return 0;
}