문제
정수로 이루어진 리스트 num_list가 주어집니다. num_list에서 가장 작은 5개의 수를 제외한 수들을 오름차순으로 담은 리스트를 return하도록 solution 함수를 완성해주세요.
솔루션
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
// num_list_len은 배열 num_list의 길이입니다.
int* solution(int num_list[], size_t num_list_len) {
// return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
int* answer = (int*)malloc(num_list_len*sizeof(int));
int tmp;
int i;
for(i = 0; i < num_list_len; i++)
for(int j = i+1; j < num_list_len; j++)
if(num_list[i] > num_list[j])
{
tmp = num_list[i];
num_list[i] = num_list[j];
num_list[j] = tmp;
}
int k = 0;
for(i = 5; i < num_list_len; i++)
answer[k++] = num_list[i];
return answer;
}
https://school.programmers.co.kr/learn/courses/30/lessons/181852
'프로그래머스코딩테스트연습풀이 > C언어' 카테고리의 다른 글
[프로그래머스/C언어] 문자열 정수의 합 (0) | 2023.08.02 |
---|---|
[프로그래머스/C언어] 정수 부분 (0) | 2023.08.02 |
[프로그래머스/C언어] 배열의 길이에 따라 다른 연산하기 (0) | 2023.08.02 |
[프로그래머스/C언어] 배열 비교하기 (0) | 2023.08.02 |
[프로그래머스/C언어] 배열의 원소만큼 추가하기 (0) | 2023.08.02 |