//雙斜線後面表示為註解
#include <stdio.h> //包含 printf function 的標頭檔
#include <stdlib.h> //包含 srand, rand function 的標頭檔
#include <time.h> //包含 time function 的標頭檔
void main() { //主程式開始
int a; //宣告一個整數integer的變數variable
int n;
srand(time(NULL)); //產生每次變數均不同的效果;用 srand() 函數改變一開始的亂數值
for (n=1; n <= 10; n++) { //for 迴圈loop , n=1開始, 當n<=10時, 執行 loop 內的指令, 執行完畢 n+1
a=(rand()%100)+1; //計算, 取 1-100 的亂數
printf("The %ith Random Number is %d .\n", n, a); //印出第n個隨機數的字串
} // for 迴圈loop 程式碼區塊結束
} //主程式結束
沒有留言:
張貼留言