Jungol Algorithm/Language Coder

정올 CODE 159 배열1 - 형성평가10

치조 2022. 11. 16. 00:44
반응형

문제

20 이하의 정수 n을 입력받고 n명의 점수를 입력받아 높은 점수부터 차례로 출력하는 프로그램을 작성하시오.

 

입력 예

5
35 10 35 100 64

 

출력 예

100
64
35
35
10

 

CODE

#include<stdio.h>
int main(){
	int n, temp;
	scanf("%d",&n);
	int score[n] = {0,};
	for(int i=0; i<n; i++){
		scanf("%d",&score[i]);
	}
	for(int i=0; i<n - 1; i++){
		for(int j=0; j<n -1; j++){
			if(!(score[j] > score[j+1])){
			temp = score[j];
			score[j] = score[j+1];
			score[j+1] = temp;
			}
		}
	}
	for(int i=0; i<n; i++)
	printf("%d\n",score[i]);
}

질문은 댓글로 받습니다. 감사합니다.

 

 

 

반응형