알고리즘/기본 문법
2022. 4. 22.
<알고리즘> 배열의 합(accumulate())
함수 정의 template constexpr T accumulate( InputIt first, InputIt last, T init ) 인자로는 first, last, 초기값이 들어간다. T형태로 그대로 리턴되므로 값 초과에 유의해서 초기값을 넣어주면 된다. 코드 #include using namespace std; int main() { vector v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int sum = accumulate(v.begin(), v.end(), 0); // #include cout