numar ce se repeta in vector

Se citeste un vector. Sase afiseze de cate ori apare un nr ce se repeta

#include <iostream>
using namespace std;

int main()

{

int aux,n,i,j,nr,a[20];
cout<<“n=”;cin>>n;
for (i=1;i<=n;i++)
{cout<<“a[“<<i<<“]=”;cin>>a[i];}
aux=-1;
for(i=1;i<=n;i++)
{nr=1;
if(a[i]!=aux)
{for(j=i+1;j<=n;j++)
if(a[i]==a[j]) {nr++;a[j]=aux;}
cout<<“nr”<<a[i]<<“apare de “<<nr<<” ori”;
cout<<endl;}
}

return 0;
}

Leave a Comment

%d bloggers like this: