Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

Write a C program to print all unique elements in the array.

#include <stdio.h>
int main()
{
    int arr1[100], n,ctr=0;
    int i, j, k;
       printf("Input the number of elements to be stored in the array: ");
       scanf("%d",&n);
       printf("Input %d elements in the array :
",n);
       for(i=0;i<n;i++)
            {
	      printf("element - %d : ",i);
	      scanf("%d",&arr1[i]);
	    }
    printf("
The unique elements found in the array are: 
");
    for(i=0; i<n; i++)
    {
        ctr=0;
        for(j=0,k=n; j<k+1; j++)
        {
            if (i!=j)
            {
		       if(arr1[i]==arr1[j])
              {
                 ctr++;
               }
             }
        }
       if(ctr==0)
        {
          printf("%d ",arr1[i]);
        }
    }
       printf("

");
}
 
PREVIOUS NEXT
Tagged: #Write #C #program #print #unique #elements
ADD COMMENT
Topic
Name
9+3 =