马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
想问一下bili为什么等于0?
sumcishu[i] 和cishu都不为0#if(1)
#include <stdio.h>
#include <time.h>
double moni()
{
int i;
double bili;
int y = 0;
int z = 0;
int suiji;
int sum = 0;
int shijian;
int switch2;
int cishu;
int chushi=0;
int sjs[100] = { 0 };
char shijianming[99][99];
double gailv[99] = { 0 };
int sumcishu[99] = { 0 };
double gailvsum = 0;
printf("有几个事件?\n");
scanf_s("%d", &shijian);
for (;;)
{
y = 0;
sum = 0;
for (i = 0;i < shijian;i++)
{
printf("输入第%d个事件是什么\n", i + 1);
scanf_s("%s", shijianming[i], 99);
printf("输入第%d个事件的概率(0.01至1)\n", i + 1);
scanf_s("%lf", &gailv[i]);
sum = sum + gailv[i] * 100;
for (;y < sum;y++)
{
sjs[y] = i;
}
gailvsum = gailvsum + gailv[i];
}
if (gailvsum != 1)
{
printf("输入的概率总和不为1,请重新输入\n");
gailvsum = 0;
system("pause");
system("cls");
}
else
{
break;
}
}
for (;;)
{
printf("输入1进行单步测试,输入2进行指定次数调试\n");
scanf_s("%d", &switch2);
switch (switch2)
{
case(1):
break;
case(2):
printf("你想进行多少次测试?\n");
scanf_s("%d", &cishu);
srand((unsigned)time(NULL));
for (z = 0;z < cishu;z++)
{
suiji = rand() % 99 + 0;
sumcishu[sjs[suiji]]++;
printf("第%d次:%s\n", z + 1, shijianming[sjs[suiji]]);
}
for (i = 0;i < shijian;i++)
{
bili = sumcishu[i] / cishu;
printf("其中%s的次数为%d,占比为%d%%\n", shijianming[i], sumcishu[i], bili);
}
break;
default:
printf("输入1或者2");
system("pause");
system("cls");
}
}
}
void main()
{
int switch1 = 0;
printf("输入1进行模拟实验,输入2进入概率计算。\n");
switch1 = scanf_s("%d", &switch1);
if (switch1 == 1)
{
moni();
}
}
#endif
|