title: Prime number into an array in C
body: <p>I try to do a function in order to sort an array and display after that only the prime number. But all the elements of my array are random numbers, and the problem is that the function display only negative prime numbers and not positive like 7 and 3, what can I do in order to solve the problem</p>
  
  <pre><code>int prime_arr(int size, int *arr, int *sort_arr)
  {
      int i, j, k = 0, flag;
      for (i = 0; i &lt; size; i++)
      {
          flag = 0;
          for (j = 2; j &lt; arr[i]/2; j++)
          {
              if (arr[i] % j == 0){
                  flag = 1;
                  break;
              }
          }
          if (flag == 0){
              sort_arr[k++] = arr[i];
          }
      }
      return j;
  }
  </code></pre>