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

}

運行神則截圖:

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:710
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:972
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:681
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:833
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:741
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1081
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:312
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:192
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:879
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:837