C++ Programe To Find All Repeated Elements Present In 1D Array

C++ Programe To Find All Repeated Elements Present In 1D Array

//C++ Programe To Find All Repeated Elements Present In 1D Array
#include<iostream>

using namespace std;
int main()

{
int array1[20],n,i,j,num,counts;

cout<<"Enter The No. Of Elements Of Array(Max. 20):--";
cin>>n;

cout<<"Enter Elements Of Array1:--\n";
for(i=0;i<n;i++)
{cout<<"Enter the "<<i+1<<"th Element:--";
cin>>array1[i];}

cout<<"\nElements Of Array1:--";
for(i=0;i<n;i++)
cout<<array1[i]<<",";
cout<<"\nAll Repeated Number :--";
for(i=0;i<n;i++)
   {   counts=0;
       num=array1[i];
       for(j=i+1;j<n;j++)
        {if(array1[j]==num)
            counts++;
        }
        if(counts==1)
        cout<<num<<",";

   }
return 0;
}

Post a Comment

0 Comments