title: Finding the average, maximum, minimum value of array in c
body: <p>I am trying to get the smallest and the largest values of the array. An array which is created by user. I keep getting <code>Segmentation fault (core dumped)</code>. I don't know where I am doing wrong.</p>
  <pre><code>#include &lt;stdio.h&gt;
  int main(void){
      int n, i;
      double sum = 0.0, array[n], avg;
      printf(&quot;Enter the size of the array:&quot;);
      scanf(&quot;%d&quot;, &amp;n);
  
      for (i=0; i&lt;n; ++i){
          printf(&quot;Enter the number for position %d: &quot;, i + 1);
          scanf(&quot;%i&quot;, &amp;n);
          sum += n;
      }
      avg = (double) sum / n;
      printf(&quot;Average = %.2f\n&quot;, avg);
          
      double largest = array[0], smallest = array[0];
  
      for (i = 0; i &lt; n; i++){
          if (array[i] &gt; largest)
          {
              largest = array[i];
          }
          else if (array[i] &lt; smallest)
          {
              smallest = array[i];
          }
      }
      printf(&quot;The smallest is %lf and the largest is %lf!\n&quot;, smallest, largest);    
  }
  </code></pre>
  <p>Edit: After solving this problem, I saw that I also can't get the smallest and largest values. I keeps giving <code>0.000000</code> for both. How do I solve it? I tried the change <code>double</code> to <code>float</code> but didn't work..</p>