當前位置:首頁 » 編程語言 » c語言隨機數生成1000

c語言隨機數生成1000

發布時間: 2024-09-07 08:28:27

c語言:從10000到99999之間產生1000個隨機數,並從小到大排序,且需要輸出序列號。

代碼:

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <time.h>

struct num_list

{

int id;

int num;

};

int main()

{

num_list n_list[1000];

srand((unsigned)time(NULL));

for (int i = 0; i < 1000; i++) {

int current_n = rand() % 89999 + 10000;

n_list[i].id = i + 1;

n_list[i].num = current_n;

}

for (int i = 0; i < 1000; i++)

{

for (int j = i + 1; j < 1000; j++)

{

if (n_list[i].num > n_list[j].num)

{

int id_temp = n_list[j].id;

int num_temp = n_list[j].num;

n_list[j].id = n_list[i].id;

n_list[j].num = n_list[i].num;

n_list[i].id = id_temp;

n_list[i].num = num_temp;

}

}

}

for (int i = 0; i <敬改 1000; i++)

{

printf("序號:%d 亮瞎判 值:%d ", n_list[i].id, n_list[i].num);

}

return 0;

}

運行神則截圖:

熱點內容
使用jsp腳本輸出九九乘法表 發布:2025-09-18 05:22:11 瀏覽:662
出行解壓 發布:2025-09-18 05:20:54 瀏覽:573
安卓手機畫線怎麼用 發布:2025-09-18 05:16:43 瀏覽:696
解壓吃蔬菜 發布:2025-09-18 05:10:04 瀏覽:817
php判斷數組個數 發布:2025-09-18 04:54:02 瀏覽:663
linuxmd5c 發布:2025-09-18 04:47:04 瀏覽:344
數據結構編譯器哪個好 發布:2025-09-18 04:33:52 瀏覽:437
ad轉換c語言 發布:2025-09-18 04:21:21 瀏覽:753
sqlserver2008設置外鍵 發布:2025-09-18 04:21:12 瀏覽:115
伺服器電腦電源管理 發布:2025-09-18 03:52:33 瀏覽:327