read n numbers and print count of distinct elements of array
int main() {
int n[15];
int sz,k;
int i,j,b=1,d=0;
scanf("%d",&sz);
for(k=0;k<sz;k++)
scanf("%d",&n[k]);
for(i=0;i<sz;i++)
{
d++;
for(j=i+1;j<sz;j++)
{
if(n[i]==n[j] && b==1)
{
d--;
b=0;
}
}
b=1;
}
printf("\n%d", d);
}
No comments:
Post a Comment