1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <stdlib.h>
 
using namespace std;
void main(){
    int *arr,input,temp;
 
    cout<<"입력:";
    cin>>input;
 
    arr=(int*)malloc((input+1)*4);
 
    cout<<"변경전: ";
    for(int j=0;j<input;j++) {
        arr[j] = j;
        cout<<arr[j]<<" ";
    }
 
    for (int j=0; j<input; j++){
        int rnd1 = rand() % input;
        int rnd2 = rand() % input;
        temp = arr[rnd1];
        arr[rnd1] = arr[rnd2];
        arr[rnd2] = temp;
    }
 
    cout<<"\n변경후: ";
    for(int j=0;j<input;j++)
        cout<<arr[j]<<" ";
 
    cout<<"\n";
    free(arr);
}
cs


+ Recent posts