回覆列表
  • 1 # dadazhu2

    如何運用time函式和srand函式生成隨機數

    #include <stdio.h>

    #include <stdlib.h>//srand()、rand()

    #include <time.h>//time();

    #include <conio.h>

    #define N 50

    int main()

    {

    int n;

    srand((unsigned)time(NULL));//設定隨機數種子

    while (1)

    {

    n = (rand() % 10) + 1 ;//產生1~10的隨機數

    //rand()產生的是一個很大的數,對其求餘就可以達到限定範圍的目的

    printf("%d ", n);

    getch();

    }

    return 0;

    }

  • 中秋節和大豐收的關聯?
  • Photoshop中如何連續複製?