Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

C program to find non-repeating elements in an array

Non-repeating elements of an array

In this section, we will learn the Java Program to Find the Elements that do Not have Duplicates 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.

Java program for conting non repeating elements in an array

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