티스토리 뷰
주어진 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int scores[], int scores_len, int cutline) {
int answer = 0;
//빈칸
return answer;
}
int main() {
int scores[5] = { 80, 90, 55, 60, 59 };
int scores_len = 5;
int cutline = 60;
int ret = solution(scores, scores_len, cutline);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret);
}
완성 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int scores[], int scores_len, int cutline) {
int answer = 0;
for (int i = 0; i < scores_len; i++) {
if (scores[i] >= cutline) answer++;
}
return answer;
}
int main() {
int scores[5] = { 80, 90, 55, 60, 59 };
int scores_len = 5;
int cutline = 60;
int ret = solution(scores, scores_len, cutline);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret);
}
예시
scores | scores_len | cutline | return |
[80, 90, 55, 60, 59] | 5 | 60 | 3 |
부가설명
각 배열에 담긴 점수가 지정된 커트라인 이상일 때, 합격이므로
for문과 >=연산자를 사용하여
커트라인보다 같거나 클 경우
합격자 수 answer++를 실행시켰다.
goorm
구름은 클라우드 기술을 이용하여 누구나 코딩을 배우고, 실력을 평가하고, 소프트웨어를 개발할 수 있는 클라우드 소프트웨어 생태계입니다.
www.goorm.io
'[코테] > [GroomEdu]' 카테고리의 다른 글
[COS PRO 2급] 5차 2번_공강시간 구하기 (C/C++) (0) | 2021.05.23 |
---|---|
[COS PRO 2급] 4차 9번_위험한 지역 몇개인지 알려주기 (C/C++) (0) | 2021.05.22 |
[COS PRO 2급] 4차 7번_오른 점수와 떨어진 점수 구하기 (C/C++) (0) | 2021.05.21 |
[COS PRO 2급] 4차 8번_누가 반장이 될까요 (C/C++) (0) | 2021.05.21 |
[COS PRO 2급] 4차 5번_다이어트하는 A씨의 추가 운동 여부 알려주기 (C/C++) (0) | 2021.05.20 |
댓글
공지사항
최근에 올라온 글
TAG
- 프로그래머스
- c언어 기출문제
- groomedu
- 코스프로
- cospro기출문제
- 배열
- Java
- programmers
- lv1
- 배열활용문제
- 구름에듀 기출문제
- lv2
- CosPro
- 구름에듀
- C++
- groom
- 코딩테스트
- YBM기출
- 구름 기출문제
- YBM
- c언어
- cospro기출
- 1급
- 자바
- Cos Pro
- C
- 알고리즘
- 연습문제
- 기출문제
- COSPRO 2급
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함