answersLogoWhite

0


Best Answer

#include

int main(){

int arr[50];

int *p;

int i,j,k,size,n;

printf("\nEnter size of the array: ");

scanf("%d",&n);

printf("\nEnter %d elements into the array: ",n);

for(i=0;i

scanf("%d",&arr[i]);

size=n;

p=arr;

for(i=0;i

for(j=0;j

if(i==j){

continue;

}

else if(*(p+i)==*(p+j)){

k=j;

size--;

while(k < size){

*(p+k)=*(p+k+1);

k++;

}

j=0;

}

}

}

printf("\nThe array after removing duplicates is: ");

for(i=0;i < size;i++){

printf(" %d",arr[i]);

}

return 0;

}

By Amandeep Singh :)

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C program to remove duplicate elements in an array?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the algorithm using c to delete duplicate elements from an array?

To detect the duplicate, you will have to write a nested loop that compares each element with all the previous elements.To actually delete the duplicate, once you find it, you have to move over all the elements after the duplicate. If the order of the elements doesn't matter, it is faster to just move the LAST array element, overwriting the duplicate element. Use a variable to keep track how many elements of the array are "usable". For example, if your array had 10 elements, and you delete 1, the array size will still be 10... but (after moving the elements over) only 9 of those elements have useful information.


How do you write c program to perform sum of elements of matrix using pointers with functions?

i cant write


How do you write a java program to find the transpose of the matrix for the given elements?

You basically write a nested for loop (one for within another one), to copy the elements of the matrix to a new matrix.


HOW TO SOLVE 'C' problem?

1. write a 'c' program to read 4(four)numbers from a file 'BANK' and calculate the average of the numbers.Now print the calculated average in another output file 'AVERAGE' 2. write a 'c' program that finds the sum and average of inputted five integer numbers of the array using dynamic memory allocation function malloc(). 3. write a 'c' program to create simple elements 1,2,3,4 in the link list of 4(four)nodes and display the list's elements. 4. write a 'c' program to convert the expression (A+B)/(C+D) into postfix expression into stack.and then evaluate it for A=10,B=20,C=15,D=5 and display the stack status after each operation. 5. write a 'c' programto create a linked list implemented on an array containing the following numbers:1,2,3,3,3,4,4,9 and pack it to remove the duplicate numbers.so that only the following data are contained by the nodes:1,2,3,4,9


Write a C program using dynamic memory allocation to find the sum of elements of a matrix?

Did you know that memory allocation is not needed to display the matrix? However, the C program is to find the sum of all the elements.


How do you write a program that calculates the sum of the matrix elements given numbers?

ring me and ill explain - 086 22222222222222227 ring me


What tool is used to duplicate blocks on TheVoxelBox in Minecraft?

write&quot;/more&quot; in comands


How to write program for secant method in mathematica?

How to write a program for secant method by mathematica


What is program data dependence?

Program data dependence refers to the coupling of data stored in files and the specific programs required to update and maintain those files such that changes in programs require changes to the data. In a tradition file environment, any change in a software program could require a change in the data accessed by that program.


How can I stop Open Office Writer from inserting a date 01slash04slash09 when I write 1-4?

I tried to duplicate your 'error' - and it didn't do it on my copy of writer (OpenOffice version 3.3) - However, in the Calc program, it did change the format. The solution there, was to re-format the cell.


Write a program in Lex to eliminate white space and collect numbers as a token?

write a lex program to delete space from the program


How do you write Square program using vb?

write a vb program to find the magic square