C program to find non-repeating elements in an array

Non-repeating elements of an array

Today we will learn the Java Program to Find the Non Repeating elements in an Array or the elements that do not repeat itself.

Given an array, print all element whose frequency is one.

Example

Input: a[]= { 1,2,5,2,6,7,5 }
Output: 
1,6,7

There is three number which has one frequency.

so there is three number which is not repeated.

Non Repeating elements in an array in C
Non Repeating elements in an Array in C

Algorithm

Step 1. Input the size of array from the user.

Step 2. Input the elements of array from the user.

Step 3. Count the frequency of each element.

Step 4. If it is equal to 1, Print the elements of new array

C Program

#include <stdio.h>  
int main()  
{
    int n, i , j, count=0, unique = 0;;
    printf("enter size : ");
    scanf("%d",&n);
    int arr[n];
    printf("enter elements : ");
    for(i=0; i<n; i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0; i<n; i++)
    {
        count = 0;
        for(j=0; j<n; j++)
        {
            if(arr[i]==arr[j])
            {
                count++;
            }
        }
        if(count==1)
        {
            printf("%d ",arr[i]);
        }
    }
    return 0;
}  
output

Enter size of an array
6
Enter elements of array
12 2 12 3 9 2
3 9