#include <iostream>
#include <cstdlib>
#include <ctime>
int main()
{
constexprint ROWS { 2 };
constexprint COLS { 5 };
srand((unsigned) time(NULL));
int E[ROWS][COLS];
std::cout << "Matz - " << ROWS << " x " << COLS << "\n\n";
for (int row { }; row < ROWS; row++)
{
for (int col { }; col < COLS; col++)
{
E[row][col] = rand() % 10;
std::cout << E[row][col] << ' ';
}
std::cout << '\n';
}
std::cout << '\n';
int sum { };
// don't you want a sum of all the numbers?
// not those in just one row?
for (int col { }; col < COLS; col++)
{
sum += E[0][col];
}
int a { sum / COLS };
std::cout << a << '\n';
}
#include <random>
#include <iostream>
#include <algorithm>
#include <numeric>
int main()
{
const size_t noRow {2};
const size_t noCol {5};
auto rand {std::mt19937 {std::random_device {}()}};
auto randNo {std::uniform_int_distribution<size_t> {0, 9}};
int E[noRow][noCol] {};
for (auto& r : E)
for (auto& e : r)
e = randNo(rand);
// Sum and average per row
for (constauto& r : E) {
constauto sum {std::accumulate(std::begin(r), std::end(r), 0)};
std::cout << "Row sum: " << sum << ", average (int): " << sum / noCol << '\n';
}
}