Created
November 6, 2022 18:00
-
-
Save faisal95bd/2f3706d4732a69a5d3566a49c36968e3 to your computer and use it in GitHub Desktop.
Remove duplicate values from an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int arr[100]; | |
int size; | |
int i, j, k; | |
printf("Enter size of the array or total numbers : "); | |
scanf("%d", &size); | |
printf("Enter the elements of the array : "); | |
for(i=0; i<size; i++) | |
{ | |
scanf("%d", &arr[i]); | |
} | |
for(i=0; i<size; i++) | |
{ | |
for(j=i+1; j<size; j++) | |
{ | |
if(arr[i] == arr[j]) | |
{ | |
for(k=j; k < size - 1; k++) | |
{ | |
arr[k] = arr[k + 1]; | |
} | |
size--; | |
j--; | |
} | |
} | |
} | |
printf("\n\nAfter deleting the duplicates the final output: "); | |
for(i=0; i<size; i++) | |
{ | |
printf("%d\t", arr[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment