C Program to Delete Duplicates Element from Array

Write C Program to Delete Duplicates Element from Array

// C Program to Delete Duplicates Element from Array

#include <stdio.h>

int main()
{
	int A[] = {1, 2, 6, 16, 58, 17, 7, 777}, n, i, j, k, l, m;

	n = sizeof(A) / sizeof(A[0]);

    printf("Array A :--> ");
	for(i=0; i<n; i++)
        printf("%d  ", A[i]);



	for(i = 0; i < n; i++)
	{
		for(j = i+1; j < n-1; j++)
		{
			if(A[i] == A[j])
			{
				for(k = j; k < n; k++)
				{
					A[k] = A[k+1];
				}
				j--;
				n--;
			}
		}
	}

    printf("\nUpdated Array :--> ");
	for(i = 0; i < n ;i++)
	{
		printf("%d ", A[i]);
	}

	return 0;
}

Output:

Run 1:
Array A :--> 1  2  6  6  58  7  7  777
Updated Array :--> 1 2 6 58 7 777

Run 2:
Array A :--> 1  2  6  16  58  17  7  777
Updated Array :--> 1 2 6 16 58 17 7 777

≪ Previous | Next ≫