title: Find Maximum Difference using array
body: <pre><code>#include &lt;iostream&gt;
  using std::cin;
  using std::cout;
  using std::endl;
  int main()
  {
      int num;
      long long max = 0;
      long long min;
      cin &gt;&gt; num;
      long long *ptr = new long long[num];
      for (int x = 0; x &lt; num; x++)
      {
          cin &gt;&gt; ptr[x];
      }
      cout &lt;&lt; &quot;ptr for first elemnt&quot; &lt;&lt; endl;
      cout &lt;&lt; ptr[0];
      for (int x = 1; x &lt; num; x++) // 1 4 6 3 min 1  max 1
      {
          max = ptr[0];
          if (max &lt; ptr[x])
              max = ptr[x];
          min = ptr[0];
          if (min &gt; ptr[x])
              min = ptr[x];
      }
  
      cout &lt;&lt; &quot;max value &quot; &lt;&lt; max;
      cout &lt;&lt; &quot;Min value is &quot; &lt;&lt; min;
      cout &lt;&lt; max - min; // biggest number minues smallest number
  
      return 0;
  }
  </code></pre>
  <p>I try to find max difference between number in array but so i get max and min number in array which have biggest difference but i when i check the max value and min value i find them wrong so why that happen?</p>