You must Sign In to post a response.
- Category: Software
- #25283Hope this code helps to solve the problem,
void rmdup(int *array, int length)
int *current , *end = array + length - 1;
for(current = array + 1;array < end;array++,current=array+1 )
while ( current < end )
if ( *current == *array )
*current = *end--;
- #25495hi this is jayaram,
ALGORITHM TO REMOVE THE DUPLICATE NUMBERS IN AN ARRAY:
*HEADER FILE DECLARATION:
*GETTING ARRAY OF ELEMENTS FROM THE USER:
printf("\nEnter the Array size:");
printf("\nEnter the array elements");
*REMOVING THE DUPLICATE ELEMENTS FROM THE ARRAY
*THE NEW ARRAY ELEMENTS WITHOUT DUPLICATION :
printf("\nThe new array elements are follows\n");
this removes all the duplicate numbers in the given array.
- #25511Hello Friend,
You are asking about the algorithm so the required algorithm may be as below.
Step 1. Start
Step 2. Declare variables two more than that of number of elements in array.
( say number of elements in array is 5 ). Declare 7 variables viz a,b,c,d,e,f,g. It is better to declare an array and two variables but you can declare all variables. Initialize all variable with 0 value.
Step 3. Now add the value of array elements in variables. Something like
a<-array and so on as
Step 4. After completing this step your last two declared variables will be still 0.
Set second last variable to the number of elements in this case it is 5.
Step 5. Repeat step 6 to 8, 5(f) time.
Step 6. Initialize last variable, g in this case with first array element, a here. And compare g with each array element. If the variable g matches with any initialize the element to 0. Please note that the initial array must not have any 0 before if it has, set the value to -1 for duplicate element or any other value that is not present in array.
Step 7. After completing the loop set g to second array element and repeat step 6.
Step 8. Repeat above steps for all array elements.
This is the exact algorithm.
In exact form it looks like this
this is complete algorithm for the above problem.
- #26124The algorithm-
Step 1. Input the Array.
Step 2. Arrange the Array in decreasing or increasing order as you wish but with a constraint that include a equal to condition in that now from here there can be two ways.
Step 2.a Now as you go on arranging the numbers in decreasing order you can keep deleting a number every time you see that the equal to condition has become true OR
Step 2.b you can let the array get arranged and then check every element to its next element one by one if they are equal then delete that entry and shift the whole array by one (YOU CAN WRITE A SIMPLE PROGRAM TO SHIFT THE ARRAY BY ONE ) every time an equal value is encountered the one of the value gets deleted and then array shifting put it in a loop until whole array is checked.
Step 3. The duplication in array has been removed.
Step 4. Display the Array
Step 5.End the Algorithm.