In this program, you will learn how to delete the duplicate elements from an array in c programming language.
We have designed this program for beginners for learning purpose. Copy below c program and execute it with c compiler to see the output of the program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include<stdio.h> int main() { int arr[20], i, j, k, size; printf("\nPlease enter the array size: "); scanf("%d", &size); printf("\nAcceptable Numbers: "); for (i = 0; i < size; i++) scanf("%d", &arr[i]); printf("\nArray with Unique elements: "); for (i = 0; i < size; i++) { for (j = i + 1; j < size;) { if (arr[j] == arr[i]) { for (k = j; k < size; k++) { arr[k] = arr[k + 1]; } size--; } else j++; } } for (i = 0; i < size; i++) { printf("%d ", arr[i]); } return (0); } |
Please enter the array size: 8
Acceptable Numbers: 3 9 5 3 8 9 3
Array with Unique elements: 3 5 8 9
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: c program, c program examples, c program examples with output, c program list, c programs