본문 바로가기
코딩 테스트/[c언어] cos pro 2급 기출문제

[No.34] 조교의 수 구하기 / cos pro 2급 c언어 기출 문제

by M개발자 2021. 5. 19.
반응형

조교의 수 구하기


문제 설명

 

프로그래밍 수업 n개를 동시에 진행할 때, 필요한 조교 수를 알아보려고 합니다. 조교 1명이 m명의 학생을 담당합니다.


예시

 

classes classes_len m return
[80, 45, 33, 20] 4 30 8

 


코드 해석 및 전체 코드

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int classes[], int classes_len, int m) {
	int answer = 0;
	for (int i = 0; i < classes_len; i++) {
		answer += classes[i] / m;
		if (classes[i] - m != 0)
			answer++;
	}
	return answer;
}

int main() {
	int classes[] = { 80, 45, 33, 20 };
	int m = 30;
	int ret = solution(classes, 4, m);

	printf("solution 함수의 반환 값은 %d 입니다.\n", ret);
}

cos pro 2급 기출문제

github

 

구름 goormedu COS PRO 2급 기출문제 - C언어

반응형

댓글