Write a C++ program to find duplicate elements in the given array of n size, where n is entered by the user.
Program Code:
#include<iostream>
using namespace std;
int main()
{
int i,j,n;
int array[20];
cout<<"Enter Size of array: ";
cin>>n;
cout<<endl;
cout<<"Enter elements into the array: ";
for(i=0;i<n;i++)
{
cin>>array[i];
}
cout<<endl;
cout<<"Duplicate values into the array are: ";
for(i=0; i<n; i++)
{
for(j=i+1;j<n;j++)
{
if(array[i]==array[j])
{
cout<<endl;
cout<<array[i];
}
}
}
return 0;
}
The program output is tested on www.jdoodle.com
Output:
Enter Size of array: 8
Enter elements into the array: 1 3 5 2 4 5 2 1
Duplicate Values into the array are:
1
5
2
Thanks
Mukesh Rajput
Post A Comment:
0 comments: