c++ code 2d block

C++
for(size_t bx = 0; bx < width;  bx += block_width)
for(size_t by = 0; by < height; by += block_height) {
  float sum = 0;
  for(size_t x = 0; x < block_width; ++x)
  for(size_t y = 0; y < block_height; ++y) {
    sum += array[bx + x][by + y];
  }
  average = sum / (block_width * block_height);
  new_array[bx][by] = average;
}
Source

Also in C++: