728x90 반응형 배열의 평균1 프로그래머스 Level.1 평균 구하기 정수를 담고 있는 배열 arr의 평균값을 return하는 함수, solution을 완성해보세요. #include #include using namespace std; double solution(vector arr) { double answer = 0; for(int i = 0; i < arr.size(); i++){ answer += arr[i]; } return answer / arr.size(); } answer은 배열 원소의 모든 값들의 합을 구하고, return 값에서 배열의 갯수 만큼 나누어주었다. 다른사람들의 풀이를 확인해보자 #include #include #include using namespace std; double solution(vector arr) { double answer =.. 2023. 7. 5. 이전 1 다음 728x90 반응형