-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathSource.cpp
More file actions
46 lines (40 loc) · 960 Bytes
/
Source.cpp
File metadata and controls
46 lines (40 loc) · 960 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
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
int main()
{
const int arrsize = 10;
int* arr = new int[arrsize];
srand((unsigned int)time(NULL));
cout << "Array arr: " ;
for (int i = 0; i < arrsize; i++)
{
arr[i] = (rand() % 10);
cout << arr[i] << " ";
}
cout << endl;
//Given the int array arr, generate another int array output.
//whose element indiciates how many elements in arr is smaller than arr[i].
//For example, if arr is given as [5,8,5,6,8,1,5,9,5,8],
//output should be [1,6,1,5,6,0,1,9,1,6].
int* output = new int[arrsize];
cout << "Array output: ";
int p;
for (int i = 0; i < arrsize; i++) {
p = 0;
for (int j = 0; j < arrsize; j++) {
if (arr[i] < arr[j]) {
p++;
}
}
output[i] = p;
}
/***********************************
Implement the code here!
************************************/
for (int i = 0; i < arrsize; i++) {
cout << output[i] << " ";
}
return 0;
}