Skip to content

Instantly share code, notes, and snippets.

@faisal95bd
Created November 6, 2022 18:00
Show Gist options
  • Save faisal95bd/2f3706d4732a69a5d3566a49c36968e3 to your computer and use it in GitHub Desktop.
Save faisal95bd/2f3706d4732a69a5d3566a49c36968e3 to your computer and use it in GitHub Desktop.
Remove duplicate values from an array
#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