當前位置:首頁 » 編程語言 » 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;

}

運行神則截圖:

熱點內容
python數據分析實戰pdf 發布:2025-05-17 14:49:42 瀏覽:950
海瀾之家廣告腳本 發布:2025-05-17 13:56:06 瀏覽:30
手文件夾恢復 發布:2025-05-17 13:53:32 瀏覽:993
linux怎麼看進程 發布:2025-05-17 13:53:30 瀏覽:303
thinkphp欄位緩存 發布:2025-05-17 13:52:01 瀏覽:575
山靈app安卓版如何設置 發布:2025-05-17 13:51:49 瀏覽:388
帆布壓縮袋 發布:2025-05-17 13:26:27 瀏覽:457
c語言16進製表示方法 發布:2025-05-17 13:11:25 瀏覽:480
ftp單位 發布:2025-05-17 13:10:03 瀏覽:142
c語言編寫n的階乘 發布:2025-05-17 13:10:02 瀏覽:685