fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int dup(int [],int);
  5. int main()
  6. {
  7. int i,n,index,a[20];
  8. printf("Enter n value \n");
  9. scanf("%d",&n);
  10. printf("Enter array values \n");
  11. for(i=0;i<n;++i)
  12. scanf("%d",&a[i]);
  13. for(i=0;i<n;++i)
  14. {
  15. index=dup(a,n);
  16. if(index==-1)
  17. {
  18. printf("No duplicate elements");
  19. break;
  20. }
  21. else
  22. {
  23. int i; ///////////////////////////////////// <--- fixed
  24. a[index]=0;
  25. for(i=index;i<n;i++)
  26. a[i]=a[i+1];
  27. n-=1;
  28. }
  29. }
  30. printf("Output: \n");
  31. for(i=0;i<n;++i)
  32. printf("%d\n",a[i]);
  33.  
  34. return (EXIT_SUCCESS);
  35. }
  36. int dup(int a[],int size)
  37. {
  38. int i,j,pos=-1;
  39. for(i=0;i<size;i++)
  40. {
  41. for(j=i+1;j<size;j++)
  42. {
  43. if(a[i]==a[j])
  44. {
  45. pos=j;
  46. return pos;
  47. }
  48. }
  49. }
  50. if(pos==-1)
  51. return pos;
  52. }
  53.  
Success #stdin #stdout 0s 2172KB
stdin
5
12 24 3 12 24
stdout
Enter n value 
Enter array values 
No duplicate elementsOutput: 
12
24
3