C/C++

Написать программу НА С++

Даны натуральное число n, действительная матрица размером n × 9 . Найти среднее арифметическое каждого из столбцов, имеющих четные номера.
SP
Sergej Pfenin
59
Вот так должно быть норм:
 #include  
#include
#include
#include
#define RAND(min, max) (rand() % ((max) - (min)) + (min))
#define n 7
using namespace std;
int main() {
srand(unsigned(time(nullptr)));
cout.setf(ios::fixed);
cout.precision(1);
const auto w = 6U;
double matrix[n][9];
for (auto& row : matrix) for (auto& x : row) x = RAND(100, 1000) / 10.0;
for (const auto& row : matrix) {
for (auto x : row) cout
Дмитрий Кудрявцев
Дмитрий Кудрявцев
87 571
Лучший ответ
#include <iostream>
#include <iomanip>
#include <ctime>
#include <string>
#define RAND(min, max) (rand() % ((max) - (min)) + (min))
#define n 7
using namespace std;
int main() {
srand(unsigned(time(nullptr)));
cout.setf(ios::fixed);
cout.precision(1);
const auto w = 6U;
double matrix[n][9];
for (auto& row : matrix) for (auto& x : row) x = RAND(100, 1000) / 10.0;
for (const auto& row : matrix) {
for (auto x : row) cout << setw(w) << x;
puts("");
}
puts("");
for (auto j = 0U; j < 9; ++j) {
auto sum = 0.0;
for (auto i = 0U; i < n; ++i) sum += matrix[i][j];
cout << setw(w) << sum / n;
}
puts("");
for (auto j = 0U; j < 9; ++j) {
auto sum = 0.0;
for (auto i = 0U; i < n; ++i) sum += matrix[i][j];
if (j & 1) cout << setw(w) << sum / n;
else cout << string(w, ' ');
}
puts("");
system("pause > nul");
}
Айбек Турдуев Забавный кадр)))
using namespace std;

int main()
{
setlocale(0, "");
int i, j, n;
cout << "n =";
cin >> n;

float A[n][9]; // выражение должно иметь константное значение.
for (i = 0; i < n; i++) {
for (i = 0; j < n; j++) {
cout << "A[" << i << ", " << j << "] =";
cin >> A[i][j];
}
}

cout << "Результат: " << "\n\r";
float sum;
for (i = 1; i < n; i += 2) {
sum = 0;
for (j = 0; j < n; j++) {
sum += A[i][j];
}
cout << i << ": " << sum / 9 << "\n\r";
}

system("pause");
return 0;
}
Alex Kataev
Alex Kataev
90
Alex Kataev тут по строчкам: https://pastebin.com/DBPdFyev