-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathSource.cpp
More file actions
43 lines (38 loc) · 975 Bytes
/
Source.cpp
File metadata and controls
43 lines (38 loc) · 975 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
#include <iostream>
#include <fstream>
#include <cstdlib>
#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: ";
/***********************************
Implement the code here!
************************************/
for (int i = 0; i < arrsize; i++) {
int cntt = 0;
for (int j = 0; j < arrsize; j++) {
if (arr[j] < arr[i]) cntt++;
}
output[i] = cntt;
}
for (int i = 0; i < arrsize; i++) {
cout << output[i] << " ";
}
return 0;
}