美文网首页
17.常用算术生成算法-accumulate

17.常用算术生成算法-accumulate

作者: lxr_ | 来源:发表于2021-05-16 10:45 被阅读0次
    #include<iostream>
    using namespace std;
    
    #include<vector>
    #include<algorithm>
    #include<functional>
    #include<numeric>
    
    //accumulate计算容器元素累加和
    //fill      向容器中添加元素
    
    void test1701()
    {
        vector<int> v;
    
        for (int i = 0; i <= 100; i++)
        {
            v.push_back(i);
        }
    
        //参数3为起始累加值,即最终结果为  100+容器的累加和
        int total=accumulate(v.begin(), v.end(), 1000);
        cout << "total=" << total << endl;
    }
    
    int main()
    {
        test1701();
    
        system("pause");
        return 0;
    }
    

    相关文章

      网友评论

          本文标题:17.常用算术生成算法-accumulate

          本文链接:https://www.haomeiwen.com/subject/wrgirltx.html