Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
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 30 31
Tags
more
Archives
Today
Total
관리 메뉴

이것저것

C언어 swea 1966 숫자를 정렬하자 본문

Language/C언어

C언어 swea 1966 숫자를 정렬하자

olivia-com 2020. 11. 19. 22:17

https://swexpertacademy.com/main/identity/anonymous/loginPage.do

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

#include <stdio.h>

int main(void) {
	int test_case, i, j, num;
	scanf_s("%d", &test_case);
	for (i = 0; i < test_case; i++) {
		scanf_s("%d", &num);
		int arr[50];
		for (j = 0; j < num; j++) {
			scanf_s("%d", &arr[j]);
		}
		int temp, k;
		for (k = 0; k < num; k++) { //버블 정렬 이용 
			for (j = 0; j < num - k - 1; j++) {
				if (arr[j] > arr[j + 1]) {
					/*for문을 이용해 [j] 번째 index와
					[j+1]번째 index를 비교해 더 큰 숫자를 뒤로 보낸다*/ 
					temp = arr[j];
					arr[j] = arr[j + 1];
					arr[j + 1] = temp;
				}
			}
		}
		printf("#%d ", i + 1);
		for (j = 0; j < num; j++) {
			printf("%d ", arr[j]);
		}
		printf("\n");
	}
	return 0;
}
​

'Language > C언어' 카테고리의 다른 글

C언어 swea 1940 가랏!RC카!  (0) 2020.11.19
C언어 swea 2001 파리퇴치  (0) 2020.11.19
C언어 swea 1976 시각 덧셈  (0) 2020.11.19
C언어 swea 1926 간단한 369게임  (0) 2020.11.19
C언어 swea 1284 수도 요즘 전쟁  (0) 2020.11.19