Home »
C programs »
C one-dimensional array programs
C program to print the non-repeated elements of an array
Here, we are going to learn how to print the non-repeated elements of an array in C programming language?
Submitted by Nidhi, on July 10, 2021
Problem statement
Here, we will create an array of integers then find non-repeated elements from the array and print them on the console screen.
Printing the non-repeated elements of an array
The source code to print the non-repeated elements of an array is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
C program to print the non-repeated elements of an array
// C program to print the non-repeated elements of an array
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[] = { 1, 2, 3, 2, 2, 5, 6, 1 };
int iLoop = 0;
int jLoop = 0;
printf("Non repeated elements are: ");
for (iLoop = 0; iLoop < 8; iLoop++) {
for (jLoop = 0; jLoop < 8; jLoop++) {
if (arr[iLoop] == arr[jLoop] && iLoop != jLoop)
break;
}
if (jLoop == 8) {
printf("%d ", arr[iLoop]);
}
}
printf("\n");
return 0;
}
Output
Non repeated elements are: 3 5 6
Explanation
Here, we created an array arr with 8 elements. Then we iterated the array elements and find non-repeated elements from the array and printed them on the console screen.
C One-Dimensional Array Programs »