Find Duplicate Elements in Array in C++

Advertisements

Find Sum of Array Element in C++ Print Triangle of Star in C++

C++ Program to Find Duplicate Elements in Array

Array is the collection of similar data type, In this program we find duplicate elements from an array, Suppose array have 3, 5, 6, 11, 5 and 7 elements, in this array 5 appear two times so this is our duplicate elements.

Find Duplicate Elements in Array in C++

#include<iostream.h>
#include<conio.h>

 void main()
 {
  int i,arr[20],j,no;
  clrscr();
  cout<<"Enter Size of array: ";
  cin>>no;
  cout<<"Enter any "<<no<<" num in array: ";
  for(i=0;i<no;i++)
  {
   cin>>arr[i];
  }
  cout<<"Dublicate Values are: ";
  for(i=0; i<no; i++)
   {
    for(j=i+1;j<no;j++)
    {
    if(arr[i]==arr[j])
    {
    cout<<"\n"<<arr[i];
    }
   }
   }
  getch();
 }

Output

Enter Size of Array : 5
Enter any 5 elements in Array: 
5 4 5 2 3 
Duplicate Elements are: 
5

Find Sum of Array Element in C++ Print Triangle of Star in C++

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements