C/C++の宿題を片付けます 81代目
■ このスレッドは過去ログ倉庫に格納されています
0162デフォルトの名無しさん
2007/01/15(月) 13:23:10#include <stdio.h>
const int max = 1000000;
int teacher(void)/* 開講: 1, 休講: 0 */
{
static int st = 1;
if (st == 0 && rand() % 10 != 0)
st = 1;
if (st == 1 && rand() % 10 < 3)
st = 0;
return st;
}
int main(int argc, char* argv[])
{
int i, count;
srand(time(NULL));
for (i = 0; i < max; i++) {
if (teacher()) { count++; }
}
printf("%d (%lf%%)¥n", count, (double)count / max * 100);
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています