-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom array
More file actions
50 lines (38 loc) · 775 Bytes
/
random array
File metadata and controls
50 lines (38 loc) · 775 Bytes
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//program for a random array
#include<bits/stdc++.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
void swap (int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void printArray (int arr[], int n)
{
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
cout << "\n";
}
void randomnumber (int arr[], int n)
{
srand (time(NULL));
for (int i = n - 1; i > 0; i--)
{
int j = rand() % (i + 1);
swap(&arr[i], &arr[j]);
}
}
int main()
{
int arr[100];
int n ;
cin>>n;
for(int i=0;i<=n;i++){
cin>>arr[i];
}
randomnumber (arr, n);
printArray(arr, n);
return 0;
}