Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ vector average

double avg1(std::vector<int> const& v) {
    return 1.0 * std::accumulate(v.begin(), v.end(), 0LL) / v.size();
}
Comment

c++ average vector

float average(std::vector<float> const& v){
    if(v.empty()) return 0;
    auto const count = static_cast<float>(v.size());
    return std::reduce(v.begin(), v.end()) / count;
}
Comment

c++ vector average

double avg1(std::vector<int> const& v) {
    return 1.0 * std::accumulate(v.begin(), v.end(), 0LL) / v.size();
}
Comment

c++ average vector

float average(std::vector<float> const& v){
    if(v.empty()) return 0;
    auto const count = static_cast<float>(v.size());
    return std::reduce(v.begin(), v.end()) / count;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: check if file is empty c++ 
Cpp :: print vector of vector c++ 
Cpp :: copy a part of a vector in another in c++ 
Cpp :: bubble sort in c+ 
Cpp :: arguments to a class instance c++ 
Cpp :: rand c++ 
Cpp :: how print fload wiht 3 decimal in c++ 
Cpp :: do while loop c++ loops continuously 
Cpp :: if vector is empty c++ 
Cpp :: string stream in c++ 
Cpp :: c++ random number between 0 and 1 
Cpp :: sieve of eratosthenes algorithm in c++ 
Cpp :: vector search by element 
Cpp :: What is the story of c++ 
Cpp :: how to erase a certain value from a vector in C++ 
Cpp :: log base 10 c++ 
Cpp :: check if character in string c++ 
Cpp :: c++ remove numbers from vector if larger than n 
Cpp :: c++ int 
Cpp :: Pyramid pattren program in C++ 
Cpp :: print a string with printf in c++ 
Cpp :: how to initialize a vector of pairs in c++ 
Cpp :: how to sort vector of struct in c++ 
Cpp :: concatenate two vectors c++ 
Cpp :: unreal engine c++ 
Cpp :: cpp mark getter as const 
Cpp :: c++ check substring 
Cpp :: c++ char array size 
Cpp :: c++ compile to exe command line 
Cpp :: print hello world in c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =