알고리즘 9 - Square(n) Sum

tamagoyakii·2021년 10월 4일
1

알고리즘

목록 보기
9/89

Q.

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

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

A)

#include <stddef.h>

int square_sum(const int *values, size_t count) {
  int ret = 0;
  for (unsigned long i = 0; i < count; i++) {
    ret += values[i] * values[i];
  }
  return ret;
};

0개의 댓글