Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <format>
- #include <vector>
- using namespace std;
- int main()
- {
- SetConsoleOutputCP(1251);
- srand(time(0));
- vector<double> C = {};
- int i{}, j{}, lines{}, columns{};
- double B{};
- while (true) {
- cout << "Введіть будь-яке число (від 1 до 98): ";
- cin >> B;
- if (cin.fail() || B < 1 || B > 98) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Число було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- while (true) {
- cout << "Введіть кількість рядків масиву (від 2 до 10): ";
- cin >> lines;
- if (cin.fail() || cin.peek() != '\n' || lines < 2 || lines > 10) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Кількість рядків було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- while (true) {
- cout << "Введіть кількість стовпців масиву (від 2 до 10): ";
- cin >> columns;
- if (cin.fail() || cin.peek() != '\n' || columns < 2 || columns > 10) {
- cin.clear();
- cin.ignore(32767, '\n');
- cout << "Кількість стовпців було введено неправильно. Спробуйте ще раз!" << endl;
- continue;
- }
- else {
- break;
- }
- }
- vector < vector <double> > A(lines, vector <double>(columns));
- cout << "Задана матриця: " << endl;
- for (i = 0; i < lines; i++) {
- for (j = 0; j < columns; j++) {
- A[i][j] = rand() % 199 - 99;
- cout << format("{:7}", A[i][j]);
- if (abs(A[i][j]) > B) {
- C.push_back(A[i][j]);
- }
- }
- cout << endl;
- }
- cout << "Вихідний масив: " << endl;
- for (i = 0; i < C.size(); i++) {
- cout << C[i];
- if (i < C.size() - 1) {
- cout << ", ";
- }
- }
- cout << endl;
- cout << "Кількість елементів, що перевищують по абсолютній величині задане число - " << C.size();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement