Home »
C programs »
C one-dimensional array programs
C program to find the total of non-repeated elements of an array
Here, we are going to learn how to find the total of non-repeated elements of an array in C programming language?
Submitted by Nidhi, on July 11, 2021
Problem statement
Here, we will create an array of integers then find non-repeated elements from the array and count them.
Finding the total of non-repeated elements of an array
The source code to find the total of 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 find the total of non-repeated elements of an array
// C program to find the total of
// 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;
int cnt = 0;
for (iLoop = 0; iLoop < 8; iLoop++) {
for (jLoop = 0; jLoop < 8; jLoop++) {
if (arr[iLoop] == arr[jLoop] && iLoop != jLoop)
break;
}
if (jLoop == 8) {
cnt = cnt + 1;
}
}
printf("Total non-repeated elements are: %d\n", cnt);
return 0;
}
Output
Total non-repeated elements are: 3
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 count them. After that, we printed a count of non-repeated elements on the console screen.
C One-Dimensional Array Programs »