-
Notifications
You must be signed in to change notification settings - Fork 59
/
duplicates.cpp
43 lines (41 loc) · 808 Bytes
/
duplicates.cpp
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>
using namespace std;
//function to find duplicates elements
void find_duplicates(int array[], int size)
{
for (int i = 0; i < size; i++)
{
for (int j = i + 1; j < size; j++)
{
if (array[i] == array[j])
{
cout << array[i];
}
}
}
}
int main()
{
int size;
cout << " Enter the size of array : ";
cin >> size;
int* array = new int[size];
//populating array
for (int i = 0; i < size; i++)
{
cout << "Enter the value of element " << i + 1 << " : ";
cin >> array[i];
}
cout << endl;
//display the array contents
cout << "Contents of array are :" << endl;
for (int i = 0; i < size; i++)
{
cout << array[i] << "\t";
}
//function call
find_duplicates(array, size);
delete[]array;
array = NULL;
return 0;
}