2023.01.11
<Coding Test> 15 day
#36 가장 큰 수 찾기

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
// array_len은 배열 array의 길이입니다.
int* solution(int array[], size_t array_len) {
// return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
int* answer = (int*)malloc(sizeof(int)*2);
int max=0;
for(int i=0; i<array_len; i++)
{
if(array[i] > array[max])
{
max = i;
}
}
answer[0]=array[max];
answer[1]=max;
return answer;
}
코딩테스트 연습 - 가장 큰 수 찾기 | 프로그래머스 스쿨 (programmers.co.kr)
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#37 n의 배수 고르기

#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 cnt=0;
for(int i=0; i<numlist_len; i++)
{
if(numlist[i]%n == 0)
cnt++;
}
int idx=0;
int* answer = (int*)malloc(sizeof(int)* cnt);
for(int i=0; i < numlist_len; i++)
{
if(numlist[i]%n == 0)
{
//answer[idx]=numlist[i];
*(answer+idx) = numlist[i];
idx++;
}
}
return answer;
}
코딩테스트 연습 - n의 배수 고르기 | 프로그래머스 스쿨 (programmers.co.kr)
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
'programmers' 카테고리의 다른 글
[c programmers] test 39 (0) | 2023.01.13 |
---|---|
[c programmers] test 38 (0) | 2023.01.12 |
[c programmers] test 35 (0) | 2023.01.10 |
[c programmers] test 34 (0) | 2023.01.09 |
[c programmers] test 32-33 (0) | 2023.01.06 |