SHARE
TWEET

Untitled

a guest Jul 18th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. int required_arr[256];
  3. int *remove_duplicate (int *old_arr,int n_old,int *new_arr,int *n_new)
  4. {
  5.     int counter=0;
  6.     for (int i=0;i<n_old;i++)
  7.     {
  8.         for (int j=i+1;j<n_old-1;j++)
  9.         {
  10.             if (old_arr[i]==old_arr[j])
  11.             {
  12.                 int temp=old_arr[i];
  13.                 old_arr[i]=old_arr[n_old-1-i];
  14.                 old_arr[n_old-1-i]=temp;
  15.                 counter++;
  16.             }
  17.         }
  18.     }
  19.     for (int i=0;i<(n_old-counter);i++)
  20.     {
  21.         new_arr[i]=old_arr[i];
  22.         n_new++;
  23.     }
  24.     return required_arr;
  25. }
  26. int main ()
  27. {
  28.     const int arr_size=20;
  29.     int arr[arr_size];
  30.     int *arr_ptr;
  31.     int new_size=0;
  32.     printf ("Enter the array: ");
  33.     fflush (stdout);
  34.     for (int i=0;i<arr_size;i++)
  35.         scanf ("%d",&arr[i]);
  36.     arr_ptr= remove_duplicate (arr,arr_size,required_arr,&new_size);
  37.     printf ("The new array is: ");
  38.     for (int i=0;i<new_size;i++)
  39.         printf ("%d",arr_ptr[i]);
  40.     printf ("\n");
  41.     printf ("The new array size is: %d",new_size);
  42.     return 0;
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top