C++ Stl functions::::

C++ STL functions , min,max,sum,accumulate,reverse etc. 

#include<bits/stdc++.h>


using namespace std;

int main(){
    int n;
    n=10;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        v[i]=rand()/10000000;
        cout<<v[i]<<" ";
    }
    cout<<endl;
    int min=*min_element(v.begin(),v.end());
    int max=*max_element(v.begin(),v.end());
    int sum=accumulate(v.begin(),v.end(),0);//0 is the initial sum
    cout<<sum<<endl;
    int ct=count(v.begin(),v.end(),85);
    cout<<ct<<endl;
    auto it=find(v.begin(),v.end(),10);
    if(it!=v.end()){
        cout<<*it<<endl;
    }
    string s="manja is ganja";
    // reverse(s.begin(),s.end());
    reverse(s.begin()+2,s.end());
    cout<<s<<endl;


    cout<<max<<endl;
    cout<<min<<endl;

}

Comments

Popular Posts