티스토리 뷰
주어진 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int scores[], int scores_len) {
int answer = 0;
//빈칸
return answer;
}
int main() {
int scores1[10] = { 35, 28, 98, 34, 20, 50, 85, 74, 71, 7 };
int scores1_len = 10;
int ret1 = solution(scores1, scores1_len);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret1);
int scores2[5] = { 1, 1, 1, 1, 1 };
int scores2_len = 5;
int ret2 = solution(scores2, scores2_len);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret2);
}

완성 코드
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int scores[], int scores_len) {
int answer = 0;
int max = -1, min = 101;
int total = 0;
for (int i = 0; i < scores_len; i++) {
if (scores[i] > max) max = i;
if (scores[i] < min) min = i;
}
for (int i = 0; i < scores_len; i++) {
if (i != min && i != max) total += scores[i];
}
answer = (int)(total / (scores_len - 2));
return answer;
}
int main() {
int scores1[10] = { 35, 28, 98, 34, 20, 50, 85, 74, 71, 7 };
int scores1_len = 10;
int ret1 = solution(scores1, scores1_len);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret1);
int scores2[5] = { 1, 1, 1, 1, 1 };
int scores2_len = 5;
int ret2 = solution(scores2, scores2_len);
printf("solution 함수의 반환 값은 %d 입니다.\n", ret2);
}
goorm
구름은 클라우드 기술을 이용하여 누구나 코딩을 배우고, 실력을 평가하고, 소프트웨어를 개발할 수 있는 클라우드 소프트웨어 생태계입니다.
www.goorm.io
'[코테] > [GroomEdu]' 카테고리의 다른 글
[COS PRO 2급] 3차 6번_타일 색칠 방법 구하기 (C/C++) (0) | 2021.05.15 |
---|---|
[COS PRO 2급] 3차 5번_여행객의 총 교통비 구하기 (C/C++) (0) | 2021.05.15 |
[COS PRO 2급] 3차 4번_단어의 오타 수정하기 (C/C++) (0) | 2021.05.14 |
[COS PRO 2급] 3차 2번_장학생 수 구하기 (C/C++) (0) | 2021.05.13 |
[COS PRO 2급] 3차 1번_학생의 등수 구하기 (C/C++) (0) | 2021.05.13 |
댓글
공지사항
최근에 올라온 글
TAG
- 코스프로
- Cos Pro
- 1급
- cospro기출문제
- 알고리즘
- 코딩테스트
- 자바
- C++
- lv2
- 배열활용문제
- 배열
- CosPro
- 기출문제
- Java
- groom
- YBM기출
- YBM
- c언어 기출문제
- 구름 기출문제
- 구름에듀 기출문제
- 구름에듀
- groomedu
- C
- COSPRO 2급
- lv1
- programmers
- cospro기출
- c언어
- 연습문제
- 프로그래머스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함