#include <iostream>
#include <cstdlib>
#include <ctime>
#include <clocale>
using namespace std;
int main() {
setlocale(LC_ALL, "Russian");
srand(time(0));
// ==========================================
// ЗАДАНИЕ 1: Одномерный массив X(N)
// ==========================================
cout << "--- Задание 1: Одномерный массив ---" << endl;
int N;
cout << "Введите размер массива N: ";
cin >> N; // Ты вводишь только количество чисел
int X[100];
cout << "Сгенерированный массив: ";
for (int i = 0; i < N; i++) {
X[i] = rand() % 50; // Компьютер сам придумывает число от 0 до 49
cout << X[i] << " "; // И сразу показывает его тебе на экране
}
cout << endl;
// Ищем максимальный элемент и его индекс
int max_val = X[0];
int max_index = 0;
for (int i = 1; i < N; i++) {
if (X[i] > max_val) {
max_val = X[i];
max_index = i;
}
}
// Считаем сумму элементов после максимального
int sum_after = 0;
for (int i = max_index + 1; i < N; i++) {
sum_after += X[i];
}
cout << "\nМаксимальный элемент: " << max_val << " (на позиции " << max_index << ")" << endl;
cout << "Сумма элементов после максимального: " << sum_after << endl << endl;
// ==========================================
// ЗАДАНИЕ 2: Матрица 8x8
// ==========================================
cout << "--- Задание 2: Матрица 8x8 ---" << endl;
const int SIZE = 8;
int matrix[SIZE][SIZE];
cout << "Сгенерированная матрица:" << endl;
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
matrix[i][j] = 1 + rand() % 9;
cout << matrix[i][j] << " ";
}
cout << endl;
}
int shaded_sum = 0;
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
if (i >= j) {
shaded_sum += matrix[i][j];
}
}
}
cout << "\nСумма в заштрихованной области: " << shaded_sum << endl;
int sums_array[4];
int array_index = 0;
for (int j = 1; j < SIZE; j += 2) {
int current_col_sum = 0;
for (int i = 0; i < SIZE; i++) {
current_col_sum += matrix[i][j];
}
sums_array[array_index] = current_col_sum;
array_index++;
}
cout << "Суммы нечетных столбцов (индексы 1, 3, 5, 7): ";
for (int i = 0; i < 4; i++) {
cout << sums_array[i] << " ";
}
cout << endl;
return 0;
}