#include<iostream>
#include<cmath>
using namespace std;
int main(int argc, char** argv)
{
int test_case;
cin>>test_case;
for(int i =1; i <= test_case; i++)
{
double sum;
sum = 0;
double average;
for (int a = 1; a <= 10; a ++){
int N;
cin >> N;
sum += N;
}
average = sum / 10;
average = round(average);
cout << "#" << i << " " << average << endl;
}
return 0;//정상종료시 반드시 0을 리턴해야합니다.
}
디버깅:
문제1) sum이 초기화되지않고 반복문이 돌아가면서 계속 누적으로 쌓였다
=> sum을 초기화 시켜줌
문제 2) sum, average를 int로 선언하여 모든 소수점들이 버림으로 계산되었다.
=> 1. sum과 average를 double로 선언하고 2. cmath를 include 하여 round 함수를 호출했다.
더 공부한 것:
cmath를 호출하여 하기 함수들을 쓸 수 있다.
1) round(a) : 반올림
2) ceil(a) : 올림
3) floor(a) : 버림