7

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <cmath> #include <iomanip> using namespace std; void task906() { const int Rows = 15, Columns = 15; double C[15][15], Sum = 0; for (int i = 0; i < 15; i++) { for (int j = 0; j < 15; j++) { C[i][j] = rand() % 201; cout << setw(3) << C[i][j] << " "; if (i == j) Sum += C[i][j]; } cout << endl; } cout << "Сумма элементов главной диагонали " << Sum << endl << endl; } void task941() { int Array[10][10]; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { Array[i][j] = rand() % 201; if (i == j) Array[i][j] = 0; cout << setw(3) << Array[i][j] << " "; } cout << endl; } cout << endl << endl; } void task1046() { int Array[10][10], CurrentElement = 0, AmountOfElements = 0, Counter = 1; cout << "Исходный массив:" << endl; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { Array[i][j] = rand() % 201 - 100; cout << setw(3) << Array[i][j] << " "; } cout << endl << endl; } //Пункт а) for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (int(Array[j][i]) % 2 == 0 && Array[j][i] > 0 && Counter == 1) AmountOfElements++, Counter = 0; } Counter = 1; } int* EvenPositiveElements = new int[AmountOfElements]; Counter = 0; cout << endl << "а)Новый одномерный массив: " << endl; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (Array[j][i] > 0 && Array[j][i] % 2 == 0) CurrentElement += Array[j][i]; } if (CurrentElement > 0) EvenPositiveElements[Counter] = CurrentElement, cout << EvenPositiveElements[Counter] << " ", Counter++; CurrentElement = 0; } cout << endl; //Конец //Пункт б) cout << "б)Новый одномерный массив: " << endl; CurrentElement = 0, Counter = 0; int NegativeElements[10]; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (Array[i][j] < 0 && Array[i][j] % 2 != 0) CurrentElement += Array[i][j]; } NegativeElements[Counter] = CurrentElement, cout << NegativeElements[Counter] << " ", CurrentElement = 0, Counter++; } cout << endl; //Конец //Пункт в) cout << "в)Новый одномерный массив: " << endl; CurrentElement = 0, Counter = 0; int NegativeElements3and7[10]; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if ((Array[i][j] % 7 == 0 || Array[i][j] % 3 == 0) && Array[i][j] < 0) CurrentElement += Array[i][j]; } NegativeElements3and7[Counter] = CurrentElement, cout << NegativeElements3and7[Counter] << " ", CurrentElement = 0, Counter++; } //Конец cout << endl << endl; } int main() { setlocale(LC_ALL, "Russian"); int Number; cout << "Вариант 4, задания: 906, 941, 976, 1011, 1046" << endl; while (true) { cout << "Введите номер задания (0, чтобы закрыть программу)..." << endl; cin >> Number; switch (Number) { case 906: task906(); break; case 941: task941(); break; case 1046: task1046(); break; case 0: return 0; default: cout << "Неверный номер задания" << endl; } } }
Editor Settings
Theme
Key bindings
Full width
Lines