#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void shuffle(int a[], int n)
{
srand(time(NULL));
int temp;
int r;
for (int i = 0; i < n; i++) {
temp = a[i];
r = rand() % n;
a[i] = a[r];
a[r] = temp;
}
}
int main(void)
{
int a[] = { 0,1,2,3,4,5,6,7,8 };
shuffle(a, 9);
for (int i = 0; i < 9; i++)
printf("a[%d] = %d\n", i, a[i]);
return 0;
}
'TEST > 자료구조와 함께 배우는 알고리즘 입문(C언어)' 카테고리의 다른 글
<2> Q13. 자료구조와 함께 배우는 알고리즘 입문 (C언어) (0) | 2020.06.29 |
---|---|
<2> Q11. 자료구조와 함께 배우는 알고리즘 입문 (C언어) (0) | 2020.06.29 |
<2> Q9. 자료구조와 함께 배우는 알고리즘 입문 (C언어) (0) | 2020.06.28 |
<2> Q8. 자료구조와 함께 배우는 알고리즘 입문 (C언어) (0) | 2020.06.28 |
<2> Q7. 자료구조와 함께 배우는 알고리즘 입문 (C언어) (0) | 2020.06.28 |