/* Write a program in C to print all unique elements in an array. */
#include <stdio.h>
int main()
{
int a[25],n,i,j,ctr=0;
printf("Enter size of an array: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("element - %d : ",i);
scanf("%d",&a[i]);
}
printf("\nThe unique elements found in the array are: \n");
for(i=0; i<n; i++)
{
ctr=0;
for(j=0; j<n; j++)
{
/*Increment the counter when the search value is duplicate.*/
if (i!=j)
if(a[i]==a[j])
ctr++;
}
if(ctr==0)
{
printf("%d ",a[i]);
}
}
}
Output
0 Comments