Writing Algorithm in C
Date: 30 Nov 2009 Posted By:
How to write an algorithm in C program to delete duplicate elements from an array?
and make money!
View All Answers:
01 Dec 2009 Member Level:
Points : 3 (
Hope 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--;
02 Dec 2009 Member Level:
Points : 5 (
hi 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.
02 Dec 2009 Member Level:
Points : 12 (
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.
07 Dec 2009 Member Level:
Points : 5 (
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.
Post answer or solution to "Writing Algorithm in C"
from Google AdSense and our revenue sharing programs by posting valid answers for this question.
to post a response.
What is command to delete all records in database?
How to get Pen Drive Driver for Windows98?
Is .NET a language or a Platform?
How to develop the C program using pseudo code.
How can a *.gp5 file be opened?
What is the better way of unix shell scripting?
Boot loader problem
How to create a .con file on desktop?
What is a Digital Signature?
Return to Question Index
Ask Question to Experts
Subscribe to Email
Get Jobs by Email
Forum posts by Email
Articles by Email
Awards & Gifts
Last 7 Days
Kishori Mohon Dutta
Rajveer S Rawlin
mohamed faiyaz a
ISC Technologies, Kochi - India. Copyright © All Rights Reserved.