Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have this problem, I do not want to print the unique elements , how can I do t

ID: 3639960 • Letter: I

Question

I have this problem, I do not want to print the unique elements , how can I do this:



if the input is : 1 3 4 1 4 , the output should be : 1 4

 

#include<stdio.h>

int main()
{
int n, a[10], b[10], count = 0, c, d;

printf("Enter number of elements in array ");
scanf("%d",&n);

printf("Enter %d integers ", n);
for(c=0;c<n;c++)
scanf("%d",&a[c]);

for(c=0;c<n;c++)
{
for(d=0;d<count;d++)
{
if(a[c]==b[d])
break;
}
if(d==count)
{
b[count] = a[c];
count++;
}
}

printf("Array obtained after removing duplicate elements ");
for(c=0;c<count;c++)
printf("%d ",b[c]);

return 0;
}

Explanation / Answer

please rate - thanks

#include<stdio.h>
int main()
{
int n, a[10], b[10], count = 0, c, d;

printf("Enter number of elements in array ");
scanf("%d",&n);

printf("Enter %d integers ", n);
for(c=0;c<n;c++)
     scanf("%d",&a[c]);
printf("The duplicate elements are ");
    
for(c=0;c<n-1;c++)
   if(a[c]!=-99999)
      for(d=c+1;d<n;d++)
        if(a[c]==a[d])
           {printf("%d ",a[c]);
           a[d]=-99999;
           }
return 0;
}