프로그래머스코딩테스트연습풀이/C언어

[프로그래머스/C언어] 카운트 다운

코코쵸마 2023. 8. 1. 11:45

문제

정수 start와 end가 주어질 때, start에서 end까지 1씩 감소하는 수들을 차례로 담은 리스트를 return하도록 solution 함수를 완성해주세요.

 

솔루션

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int* solution(int start, int end) {
    // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요.
    int* answer = (int*)malloc(50 * sizeof(int));
    int j = 0;
    for(int i = start; i >= end; i--){
        answer[j++] = i;
    }
    answer[j] = "\0";
    return answer;
}

https://school.programmers.co.kr/learn/courses/30/lessons/181899

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr