close

標題:

請幫我用C++計算以下這個問題

aa.jpg

 

此文章來自奇摩知識+如有不便請留言告知

發問:

計算兩個骰子投擲100、1000和10000次,並統計兩個骰子擲出總和(2~12)出現機率! 輸出應該如下: 點數 次數 機率 [2] xxx 5.5 % [3] yyy 9.6 % . . . [12] zzz 8.6 %

最佳解答:

#include #include #include int dice2(void) { return rand()*6/(RAND_MAX+1) + rand()*6/(RAND_MAX+1); } int main(void) { double tim; int d[11], i, n; srand((unsigned) time(NULL)); rand(); for (n=100; n 改成 並加 include 一個 之後加個 using namespace std; 第一個 printf 那列改成 cout
其他解答:

#include #include #include using namespace std; int main() { srand( time( 0 ) ); int dice1, dice2; int frequency[13] = { 0 }; for( int i = 1; i

arrow
arrow
    創作者介紹
    創作者 njtnvdt 的頭像
    njtnvdt

    百科全書

    njtnvdt 發表在 痞客邦 留言(0) 人氣()