Download presentation
Presentation is loading. Please wait.
Published byAstrid Ipsen Modified 5年之前
1
隨機數 (亂數) 10後,取餘數 n = rand(); 利用 Code::Block 驗證一下 n = rand() %10; 998
產生 任何一個亂數 998 9994 利用 Code::Block 驗證一下 99 32767 29990 2 n = rand() %10; 1 3 4 10後,取餘數 5 9 6 8 7 rand() 紙牌,抽籤,六合彩,擲骰子,game,測驗
2
Q1 試寫出下列C句子中n的值。 n的可能值 (a) n = rand() %6 +1; 16 05
(b) n = rand() %10 +5; 514 09 (c) n = rand() %49 +1; 149 048 (d) n = rand() %12 +13; 1324 011 rand()
3
有多少個 不同的數? Q1 重溫 n的可能值 (a) n = rand() %6 +1; 16 6個 05
(b) n = rand() %10 +5; 514 10個 09 (c) n = rand() %49 +1; 149 49個 048 (d) n = rand() %12 +13; 1324 12個 011 rand()
4
Q2 試根據下列n的值,寫出產生n值的C句子。
有多少個 不同的數? n的可能範圍 C句子 (a) 25 n 45 (b) 17 n 33 (c) 65 n 90 (d) 48 n 57 (e) -10 n 10 21個 n = rand() %21 +25; 17個 n = rand() %17 +17; 26個 n = rand() %26 +65; 10個 n = rand() %10 +48; 21個 n = rand() %21 –10; rand()
5
(a) n = rand() %5 + rand() %4; (b) n = 10 – rand() %5;
Q3 試寫出下列C句子中n的值。 (a) n = rand() %5 + rand() %4; (b) n = 10 – rand() %5; (c) n = rand() %5 – rand() %10; (d) n = abs (rand() %5 – rand() %10); (e) ch = (char) (rand() %4 +65); 0..7 0,1,2,3,4 0,1,2,3 6..10 0,1,2,3,4 -9..4 0,1,2,3,4 0,1,2..8,9 0..9 'A' - 'D' 0,1,2,3 rand()
6
Mark VI 六合彩 main(){ int i, n; srand ( time(NULL) ); // seed i=0; do{
}while (i<6); n = rand() %49+1; printf(“ ”, ); %i n } rand()
Similar presentations