Algorithm 21 - Get the mean of an array

Beast from the east·2021년 10월 6일
0

Algorithm

목록 보기
21/27

Q.

Description:
It's the academic year's end, fateful moment of your school report. The averages must be calculated. All the students come to you and entreat you to calculate their average for them. Easy ! You just need to write a script.

Return the average of the given array rounded down to its nearest integer.

The array will never be empty.

A)

#include <stddef.h>

int get_average(const int *marks, size_t count)
{
  int sum = 0;
  for (size_t i = 0; i < count; i++)
    sum += marks[i];
  return sum / count;
}
profile
Hello, Rabbit

0개의 댓글