본문 바로가기

Algorithm

(C++) - 백준(BOJ) 1546번 : 평균

반응형
#include <iostream>
using namespace std;
int main() {
    float average=0, best = 0;
    int num;
    cin >> num;
    int *arr = new int[num];
    for (int i = 0; i < num; i++)
    {
        cin >> arr[i];
        if (best < arr[i])
        {
            best = arr[i];
        }
    }
    for (int i = 0; i < num; i++)//총점구하기
    {
            average += ((arr[i] / best) * 100);
    }
    cout << fixed;
    cout.precision(2);
    cout << average / num << '\n';
}