Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Boy of New York Bonsai Trees and Accessories

BlueHost Web Hosting

Liquid Web iThemes WordPress Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Liquid Web Cloud VPS Hosting

10,567 questions

14,363 answers

573 users

How to remove duplicate elements from int array in C

1 Answer

0 votes
#include <stdio.h>

#define LEN 8

int main() {
    int arr[LEN] = {2, 3, 2, 6, 3, 7, 9, 9};
    int len = LEN;
    
    for (int i = 0; i < len; i++) {
        for (int j = i + 1; j < len;) {
            if (arr[j] == arr[i]) {
                for (int k = j; k < len; k++) {
                    arr[k] = arr[k + 1];
                }
                len--;
            }
            else {
                j++;
            }
        }
    }

    for(int i = 0; i < len; i++) {
        printf("%2d", arr[i]);
    }

    return 0;
}



/*
run:

 2 3 6 7 9

*/

 




answered Jun 30 by avibootz
...