c++ accumulate累加函数

template< class InputIt, class T >
T accumulate( InputIt first, InputIt last, T init );

定义于头文件 <numeric>
三个参数分别是迭代器开始,迭代器结束,初始值。
例如

   int main(){
    int a[]={1,2,3,4,5};
    cout<<accumulate(a,a+5,10);
    //输出25
}
int main(){
    int a[]={1,2,3,4,5};
    cout<<accumulate(a,a+5,0);
    //输出15
}
posted @ 2019-03-10 22:45  开局一把刀  阅读(7)  评论(0)    收藏  举报