sum of diagonal elements of a matrix in c++ code example Example: sum of elements in c++ stl accumulate(a.begin(), a.end(), 0)