In a library management system auditing is a complex task for a librarian. The stock maintenance has manual entries that may have multiple entries of book access number. The library management system should be automated to remove duplicate book access number. Write a C program to remove duplicate numbers using pointer Note: Use functions and Pointers.
#include <stdio.h>
int remDuplicate(int arr[], int n)
{
      if (n == 0 || n == 1)
        return n;
    
      int temp[n];
    
      int a = 0;
      int b;
      for (b = 0; b < n - 1; b++)
        if (arr[b] != arr[b + 1])
          temp[a++] = arr[b];
      temp[a++] = arr[n - 1];
    
      for (b = 0; b< b; b++)
        arr[b] = temp[b];
    
      return a;
}
int main()
{
  int num;
  scanf("%d", &num);
  int arr[num];
  int i;
  for (i = 0; i < num; i++)
  {
    scanf("%d", &arr[i]);
  }
  printf("\nArray Before Removing Duplicates: ");
  for (i = 0; i < num; i++)
    printf("%d ", arr[i]);
  num = remDuplicate(arr, num);
  printf("\nArray After Removing Duplicates: ");
  for (i = 0; i < num; i++)
    printf("%d ", arr[i]);
  return 0;
}
Comments