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 program to remove duplicate numbers using call by reference to a funcftion.
#include<stdio.h>
#include<stdlib.h>
#include <string.h>
void removeDuplicateBookAccessNumber(int* bookAccessNumbers,int* n){
int i,j,k;
int size=*n;
/*
* Find duplicate value in array
*/
for(i=0; i<size; i++)
{
for(j=i+1; j<size; j++)
{
// If any duplicate found
if(bookAccessNumbers[i] == bookAccessNumbers[j])
{
// Delete the current duplicate element
for(k=j; k < size - 1; k++)
{
bookAccessNumbers[k] = bookAccessNumbers[k + 1];
}
size--;
j--;
}
}
}
*n=size;
}
int main( void){
int bookAccessNumbers[]={1111,5656,1111,8956,2222,6546,2222,56895,2222,50565};
int size=10,i;
printf("Book access numbers array before removing duplicates:\n");
for(i=0; i<size; i++)
{
printf("%d,",bookAccessNumbers[i]);
}
removeDuplicateBookAccessNumber(bookAccessNumbers,&size);
printf("\n\nBook access numbers array after removing duplicates:\n");
for(i=0; i<size; i++)
{
printf("%d,",bookAccessNumbers[i]);
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment