알고리즘/코드업
[코드업] 4891 행복 (C언어)
hoony_
2020. 4. 7. 02:04
반응형
버블정렬 사용하면 쉽게 풀 수 있는 문제.
C언어
#include <stdio.h>
int main() {
int students;
scanf("%d", &students);
int score[students];
for(int i=0; i<students; i++){
scanf("%d", &score[i]);
}
for(int i=0; i< students-1; i++){
for(int j=0; j< students-1;j++){
if(score[j] > score[j+1]){
int temp;
temp = score[j];
score[j] = score[j+1];
score[j+1] = temp;
}
}
}
printf("%d\n", score[students-1]-score[0]);
return 0;
}
|
반응형