Q:

C program to print the non-repeated elements of an array

0

C program to print the 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 print them on the console screen.

Program:

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

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

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 total of non-repeated elemen... >>
<< C program to print alternate elements of the array...