title: C++ How to find min and max values in a one-dimensional array of n elements?
body: <blockquote>
  <p>Write a program that asks a user to input an integer n. The program should prompt the user to input n integers and store them in a one-dimensional array. Then the program should output the minimum and maximum elements in the array.</p>
  </blockquote>
  <pre class="lang-cpp prettyprint-override"><code>int main()
  {
      int n,a,b;
      cin&gt;&gt;n;
      int ma=0,mi=0;
      int num[n];
      cin&gt;&gt;num[0];
      for(int i=1;i&lt;n;i++)
      {
          cin&gt;&gt;num[i];
          a=num[i];
          b=num[i-1];
          if(a&gt;b)
              ma=a;
          if(a&lt;b)
              mi=a;
      }
  
      cout&lt;&lt;mi&lt;&lt;endl;
      cout&lt;&lt;ma;
  }
  </code></pre>
  <p>When given elements, it doesn't show the min and max values correctly. Where is my mistake?</p>