使用了一个偷懒的算法。另外排序使用了STL函数。
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include
using namespace std;
#define NUM 10000
void main(void)
{
int rand_number[NUM];
int max = 100000;
int min = 1000;
srand(time(NULL));
for (int i = 0; i < NUM; i ++)
{
// rand number from 0 - 999999
int r = rand() % 1000 * 1000 + rand() % 1000;
// rand number from 0 - 99000
r = r % 99001 + 1000;
rand_number[i] = r;
}
sort(rand_number, rand_number+NUM);
for (i = 0; i < 100; i ++)
{
printf("%d,", rand_number[NUM-1-i]);
if ((i+1)%10 == 0)
printf("\n");
}
}