#include <stdio.h>
int a[1000];
int n, i, j, t, max;
int main() {
scanf("%d", &n); //원소의 개수
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for (i=0; i<n-1; i++)
{
max=i;
for (j=i+1; j<n; j++)
{
if(a[j] > a[max])
{
max = j;
}
}
//최댓값을 배열의 첫번째 위치부터 대입
t = a[i];
a[i] = a[max];
a[max] = t;
}
for (i=0; i<n; i++)
{
printf("%d\n", a[i]);
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: