zltzlt 发表于 2020-1-29 12:10:44

Square(n) Sum

Complete the square sum function so that it squares each number passed into it and then sums the results together.

For example, for it should return 9 because 1^2 + 2^2 + 2^2 = 9.

#include <vector>
#include <cmath>

int square_sum(const std::vector<int>& numbers)
{
    int res = 0, i;
    for (i = 0; i < numbers.size(); i++)
    {
      res += pow(numbers.at(i), 2);
    }
    return res;
}

永恒的蓝色梦想 发表于 2020-3-20 23:41:34

lambda array:sum((map(lambda n:n*n,array))){:10_248:}
页: [1]
查看完整版本: Square(n) Sum