#include <stdio.h>

int a[1000];
int n, i, j, t, min;

int main() {
    scanf("%d", &n); //원소의 개수
    
    for (i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
        
    
    for (i=0; i<n-1; i++) 
    {
        min=i;
        for (j=i+1; j<n; j++) 
        {
            if(a[j] < a[min])
            {
                min = j;
            }
        }
        //최솟값을 배열의 첫번째 위치부터 대입
        t = a[i];
        a[i] = a[min];
        a[min] = t;
    }
    
    for (i=0; i<n; i++)
    {
        printf("%d\n", a[i]);
    }
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: