WEBn/Algorithm Study
-
[C] 숫자 오름차순 만들기WEBn/Algorithm Study 2021. 8. 4. 00:32
#include int main() { int a[] = {95, 75, 85, 100, 50}; int i, j, temp; int n = sizeof(a)/sizeof(int); for(i= 0; i a[1] // 95 > 75 = true temp = 95 a[0] = a[1] = 75 a[1] = temp = 95 ∴ a[0] = 75, a[1] = 95 a[0]와 a[1]의 위치가 바뀌었다. 즉. a의 연달아 있는 두 요소를 비교했을 때 앞에 요소가 더 크다면, 순서를 바꿔준다. 그래서 i=0의 for문을 돌리면 a=[ 75 85 95 50 100 ]가 된다. i = 1 일 때 a = [ 75 85 50 95 100 ] i = 2 일 때 a = [ 75 50 85 95 100 ] i = 3 일 ..