Remove duplicates from array and save it to another one So I have been tasked to make an array without duplicated values from another existing array.
So I did it, but I want to know is there some other better way to do that.
Example input/output:
Input: 10, 15, 10, 5, 1, 3
Output: 10, 15, 5, 1, 3
So here is my code.
#include &lt;stdio.h&gt;

int main(void) {
  const int MAX_ARRAY_SIZE = 5;

  int m[MAX_ARRAY_SIZE], p[MAX_ARRAY_SIZE];


  for(int i = 0; i &lt; MAX_ARRAY_SIZE; i++) {
    printf(&quot;Enter number: &quot;);
    scanf(&quot;%d&quot;,&amp;m[i]);
  }
  int k = 0;
  int dup = 0;
  for(int i =0; i &lt; MAX_ARRAY_SIZE; i++) {
    for(int j = i +1; j &lt;MAX_ARRAY_SIZE; j++) {
        if(m[i] == m[j]) {
            dup = 1;
        }
    }
    if(dup != 1) {
      p[k++] = m[i];
    }
    dup = 0;
  }

  printf(&quot;The new array without repeated values\n&quot;);
  for(int i = 0; i &lt; k; i++) {
    printf(&quot;%d\n&quot;,p[i]);
  }

  return 0;
}

I'm not sure if this is the right and simple way I do that. I want some suggestions.
Thanks in advance. :)
Early termination
After
        dup = 1;

you should break. There's no need to execute the rest of the loop.
Booleans
Consider using &lt;stdbool.h&gt;, making bool dup = false, later assigning it true, and writing if (!dup).
Complexity
In practical terms, an array of five values poses no computational cost. However, if your prof cares about complexity analysis, the &quot;proper&quot; solution to this would need to complete in linear time (rather than your current quadratic time), using something like a hash-set, with pseudocode:
Set *seen = make_set();
for (int i = 0; i &lt; MAX_ARRAY_SIZE; i++)
{
    int m;
    scanf(&amp;m);
    if (!contains(seen, m))
        add(seen, m);
}

for (m in seen)
    printf(m);