Answer to Question #204903 in C for Swetha

Question #204903

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.


1
Expert's answer
2021-06-09T08:55:26-0400
#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;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS