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 |
#include <stdio.h> #define n 5
void selection(int a[]){ int temp; for (int i = 0; i < n - 1; i++){ for (int j = 0; j < n-i-1; j++){ if (a[j]>a[j+1]){ temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } for (int i = 0; i < n; i++){ printf("%3d", a[i]); } printf("\n"); }
int main(){ int a[] = { 8, 2, 6, 7, 4 }; int i, j;
selection(a); } |
cs |
수업
'School class' 카테고리의 다른 글
c언어)선형탐색, 이진탐색 [수업] (0) | 2019.10.11 |
---|---|
C언어) 회문 확인[수업] (0) | 2019.09.23 |
C언어)문자열 포함 확인[수업] (0) | 2019.09.23 |
C언어) 삽입정렬 (0) | 2019.09.06 |
c언어) 선택정렬 (0) | 2019.09.06 |