#include <iostream>
#include <array>
int main()
{
const size_t
size_array = 4;
size_t sum(0);
std::array<int, size_array> array[size_array]
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}
};
//1 четверть: 1, 2, 5,6
//2 четверть: 11,12,15,16
for(size_t i = 0; i < size_array; i++)
for(size_t j = 0; j < size_array; j++)
if(i < size_array / 2 && j < size_array / 2 || i >= size_array / 2 && j >= size_array / 2)
sum += array[i][j];
else continue;
}
std::cout << "Сумма элементов первой и четвертой четвертей = " << sum << std::endl;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <array>
int main()
{
const size_t
size_array = 4;
size_t sum(0);
std::array<int, size_array> array[size_array]
{
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}
};
//1 четверть: 1, 2, 5,6
//2 четверть: 11,12,15,16
for(size_t i = 0; i < size_array; i++)
{
for(size_t j = 0; j < size_array; j++)
{
if(i < size_array / 2 && j < size_array / 2 || i >= size_array / 2 && j >= size_array / 2)
sum += array[i][j];
else continue;
}
}
std::cout << "Сумма элементов первой и четвертой четвертей = " << sum << std::endl;
}