freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

[工學(xué)]第4章_程序的控制結(jié)構(gòu)第2講4[1]4~(編輯修改稿)

2025-02-15 11:57 本頁面
 

【文章內(nèi)容簡介】 為止 猜數(shù)游戲用到的庫函數(shù) ? 每次運行程序時機器所“想”的數(shù)都是一樣的,這是什么原因呢? ? 函數(shù) rand()產(chǎn)生的只是偽隨機數(shù) ? 函數(shù) srand ? 為函數(shù) rand()設(shè)置隨機數(shù)種子來實現(xiàn)對函數(shù) rand所產(chǎn)生的偽隨機數(shù)的 “隨機化” ? 通過鍵入隨機數(shù)種子,產(chǎn)生 [1,100]之間 的隨機數(shù) scanf(%u, amp。seed)。 srand(seed)。 magic = rand() % 100 + 1。 例 include include main() { int magic。 int guess。 int counter。 unsigned int seed。 printf(Please enter seed:)。 scanf(%u, amp。seed)。 srand(seed)。 magic = rand() % 100 + 1。 counter = 0。 do{ printf(Please guess a magic number:)。 scanf(%d, amp。guess)。 counter ++。 if (guess magic) printf(Wrong! Too high!\n)。 else if (guess magic) printf(Wrong! Too low!\n)。 }while (guess != magic)。 printf(Right!\n)。 printf(counter = %d \n, counter)。 } 直到猜對為止 猜數(shù)游戲用到的庫函數(shù) ? 使用計算機讀取其時鐘值并把該值自動設(shè)置為隨機數(shù)種子,產(chǎn)生 [1,100]之間 的隨機數(shù) ? 函數(shù) time()返回以秒計算的當(dāng)前時間值,該值被轉(zhuǎn)換為無符號整數(shù)并用作隨機數(shù)發(fā)生器的種子 include srand(time(NULL))。 magic = rand() % 100 + 1。 例 include include include main() { int magic。 int guess。 int counter。 srand(time(NULL))。 magic = rand() % 100 + 1。 counter = 0。 do{ printf(Please guess a magic number:)。 scanf(%d, amp。guess)。 counter ++。 if (guess magic) printf(Wrong! Too high!\n)。 else if (guess magic) printf(Wrong! Too low!\n)。 }while (guess != magic)。 printf(Right!\n)。 printf(counter = %d \n, counter)。 } 直到猜對為止 實驗 3 include include include main() { int magic。 int guess。 int counter。 srand(time(NULL))。 magic = rand() % 100 + 1。 counter = 0。 do{ printf(Please guess a magic number:)。 scanf(%d, amp。guess)。 counter ++。 if (guess magic) printf(Wrong! Too high!\n)。 else if (guess magic) printf(Wrong! Too low!\n)。 }while ((guess != magic) amp。amp。 (counter 10))。
點擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1