별의 공부 블로그 🧑🏻‍💻
728x90
728x170
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using namespace std;
 
int main() {
    const int num =5;
    int test[num];
 
    cout << num << "명의 점수를 입력하십시오. \n";
    for(int i = 0; i < num; i++) {
        cin >> test[i];
    }
 
    // 배열 정렬 (버블 정렬)
    for(int s = 0; s < num - 1; s++) {
        for(int t = s + 1; t < num; t++) {
            if(test[t] > test[s]) {     // 내림차순 정렬
                int tmp = test[t];
                test[t] = test[s];
                test[s] = tmp;
            }
        }
    }
 
    for(int j = 0; j < num; j++) {
        cout << j+1 << "번째 사람의 점수는 " << test[j] << "입니다. \n";                                  
    }
 
    return 0;
}
cs

 

버블 정렬을 이용하여 오름차순으로 배열 요소 정리 하기.

728x90
그리드형(광고전용)
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖