随机打乱数组排序

/*随机打乱数组排序*/

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define N 10

int main()
{
    srand((unsigned)time(NULL));
    int a[N] ;
    int i, j, temp;
    for(i = 0; i < N; ++i)
        a[i] = i;
    for(i = 0; i < N; ++i)
    {
        j = rand() % N;
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    for(int i = 0; i < N; ++i)
    {
        printf("%d ", a[i]);
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/ouyangenping/article/details/80059687