문제
정수 n과 정수 배열 numlist가 매개변수로 주어질 때, numlist에서 n의 배수가 아닌 수들을 제거한 배열을 return하도록 solution 함수를 완성해주세요.
솔루션
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
// numlist_len은 배열 numlist의 길이입니다.
int* solution(int n, int numlist[], size_t numlist_len) {
// return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
int* answer = (int*)malloc(numlist_len*sizeof(int));
int j = 0;
for(int i = 0; i < numlist_len; i++)
if(numlist[i] % n == 0)
answer[j++] = numlist[i];
answer[j] = '\0';
return answer;
}
https://school.programmers.co.kr/learn/courses/30/lessons/120905
'프로그래머스코딩테스트연습풀이 > C언어' 카테고리의 다른 글
[프로그래머스/C언어] 인덱스 바꾸기 (0) | 2023.08.03 |
---|---|
[프로그래머스/C언어] 가장 큰 수 찾기 (0) | 2023.08.03 |
[프로그래머스/C언어] 제곱수 판별하기 (0) | 2023.08.03 |
[프로그래머스/C언어] 세균 증식 (0) | 2023.08.03 |
[프로그래머스/C언어] l로 만들기 (0) | 2023.08.03 |