Q:

C program to find the total of non-repeated elements of an array

0

C program to find the total of non-repeated elements of an array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Here, we will create an array of integers then find non-repeated elements from the array and count them.

Program:

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

#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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

One Dimensional Array Programs / Examples in C programming language

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C program to find the missing number in the array... >>
<< C program to print the non-repeated elements of an...