Swapping largest and smallest numbers in C
<p>I want to write a program that reads 10 <code>int</code> values from the user and swaps the largest and smallest numbers on the first and second values, then the rest of the numbers should be in the order.</p>

<p>Please check the code and help me what the wrong is.</p>

<p>For instance:</p>

<pre><code>1
9
4
5
6
7
8
2
4
5
</code></pre>

<p>New order should be <code>9 1 4 5 6 7 8 2 4 5</code></p>

<pre><code>    #include &lt;stdio.h&gt;

    int main() {

    int a[10],i,min,max=0,pos=0;

    printf("Please enter 10 int values :\n");
    do{
    scanf("%d", &amp;a[pos++]);
    } while (pos&lt;10);

    for (i=0; i&lt;10;i++) {
    printf("%i\n",a[i]);

    if (max&lt;a[i])
    {
max=a[i];
}

    if (min&gt;a[i])

    {
min=a[i];
    }

    for (i=0;i&lt;10;i++) {

    if (a[i]==max) 
a[i]=max;

    if (a[i] == min) a[i] = min;

    }  

    printf("The new order is : %d %d %d ", max, min, ...);

    return 0;   
    }
</code></pre>

<p><strong>EDIT:</strong></p>

<pre><code>It is the new form

    #include &lt;stdio.h&gt;

    int main() {

        int a[10],i,pos,temp,min = 0,max = 0;

        printf("Please enter 10 int values :\n");

        do {

        scanf("%d", &amp;a[pos++]);

        } while (pos &lt; 10);

        for ( =1; i&lt;10;i++) {

        if (a[i]&gt;a[max]) 
{
max=i;
}

        if (a[i]&lt;a[min]) 
{
min=i;
}
        }

        temp=a[max];

        a[max]=a[min];

        a[min]=temp;

        printf("%d %d",a[max],a[min]);

        for (i=0;i&lt;10;i++){

        if ((i != min) &amp;&amp; (i != max)) {

        printf("%d ", a[i]);
        }

        }

        printf("\n");

        return 0;   
    }
</code></pre>