How to print the non-repeated elements of an array in C

1 Answer

0 votes
#include <stdio.h>

int main() {
    int arr[] = { 2, 4, 1, 2, 6, 4, 3, 3, 5, 7, 8, 9, 8 };
    int size = sizeof(arr) / sizeof(arr[0]);
    int j;

    for (int i = 0; i < size; i++) {
        for (j = 0; j < size; j++) {
            if (arr[i] == arr[j] && i != j)
                break;
        }
        if (j == size) {
            printf("%d ", arr[i]);
        }
    }

    return 0;
}




/*
run:

1 6 5 7 9 

*/

 



answered Jan 17, 2024 by avibootz

Related questions

1 answer 110 views
1 answer 105 views
2 answers 254 views
1 answer 274 views
1 answer 117 views
2 answers 248 views
...