title: c program for smallest and second smallest in array
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  void main()
  {
    int smallest, secondsmallest;
    int array[100], size, i;
    printf(&quot;\n How many elements do you want to enter: &quot;);
    scanf(&quot;%d&quot;, &amp;size);
    printf(&quot;\nEnter %d elements: &quot;, size);
    for (i = 0 ; i &lt; size; i++)
      scanf(&quot;%d&quot;, &amp;array[i]);
    if (array[0] &lt; array[1]) {
      smallest = array[0];
      secondsmallest = array[1];
    }
    else {
      smallest = array[1];
      secondsmallest = array[0];
    }
    for (i = 2; i &lt; size; i++) {
      if (array[i] &lt; smallest) {
          secondsmallest = smallest;
          smallest = array[i];
      }
      else if (array[i] &lt; secondsmallest) {
          secondsmallest = array[i];
      }
    }
    printf(&quot; \nSecond smallest element is %d&quot;, secondsmallest);
    printf(&quot; \n smallest element is %d&quot;, smallest);
  }
  </code></pre>
  <blockquote>
  <p>input:0 0 1 2</p>
  <p>output:smallest is 0, second smallest is 0</p>
  </blockquote>
  <p>i want to get 0,1 as output.i do not want to use sorting here.
  how can i improve my code.</p>