C/C++の宿題片付けます 124代目at TECH
C/C++の宿題片付けます 124代目 - 暇つぶし2ch435:デフォルトの名無しさん
09/03/21 03:38:25
>>420
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
int i, j, targetMoney, startMoney, currentMoney;
int totalGame = 10000, totalDice = 0, totalWin = 0;

srand(time(NULL));

printf("所持金を入力してください:");
scanf("%d", &startMoney);
printf("目標額を入力してください:");
scanf("%d", &targetMoney);

for(i=0; i<totalGame; i++) {
for(j=1, currentMoney = startMoney; ; j++) {
if((int)(rand() / (RAND_MAX + 1.0) * 6) & 1 ) currentMoney++;
else currentMoney--;
if(currentMoney == targetMoney) { totalWin++; break; }
if(currentMoney == 0) break;
}
totalDice += j;
}

printf("勝率%.2f%% 平均回数%.2f\n", 100.0 * totalWin / totalGame, (double)totalDice / totalGame);

return 0;
}


次ページ
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch