45. C Program to Remove Duplicate or Repeated Number.
How does this program work?
- In this program your going to learn about how to remove repeated number from the given array C-Language.
Here is the code
#include <stdio.h>
int main(void)
{
int array[50];
int *ptr;
int i, j, k, size, n,sum=0;
printf("\n Enter size of the array: " );
scanf("%d", &n );
printf("\n Enter %d elements of an array: ", n);
for (i = 0; i < n; i++ )
scanf("%d", &array[i] );
size = n;
ptr = array;
for (i = 0; i < size; i++)
{
for(j = 0; j < size; j++)
{
if(i == j)
{
continue;
}
else
if(*(ptr + i) == *(ptr + j))
{
k = j;
size--;
while(k < size)
{
*(ptr + k) = *(ptr + k + 1);
k++;
}
j = 0;
}
}
}
printf("\nThe array after removing duplicates is: ");
for(i = 0; i < size; i++)
{
printf(" %d\t", array[i] );
sum= sum+array[i];
}
printf("sum =\n%d",sum );
return 0;
}