Its given the matrix T[n][n] with integer elements. It is considered that the two diagonals i divide the matrix into four areas: north, south, east, west (the elements on the diagonals are not part of no area). Compose a program that will count the elements located in the northern area. Can you make this tabel just with iostream please :*
you don't need the table, all you need is n.
the first part of the sum is
* 1 2 3 4 ... * (n-2)
the next row is
** 1 2 3 4 ... ** (n-4)
so is there a pattern that just gives you the answer using only N?
There may be 2 patterns, one for even N, one for odd N, but regardless, I believe you can do it without the table if you play with it a little.
n = 3; 1
n = 4; 2
n = 5; 3 + 1
n = 6; 4 + 2
n = 7; 5 + 3 + 1
So:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
int main()
{
int n {}, cnt {};
std::cout << "Enter n: ";
std::cin >> n;
for (int i = n - 2; i > 0; i -= 2)
cnt += i;
std::cout << "Number of elements are: " << cnt << '\n';
}
#include <iostream>
int main()
{
const size_t max_size {20};
for (size_t n = 1; n <= max_size; ++n) {
size_t cnt {};
for (int i = n - 2; i > 0; i -= 2)
cnt += i;
std::cout << n << " " << cnt << '\n';
}
}