Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- srand(time(0));
- int m, n;
- m = 3; n = 4;
- int** arr = new int* [m]; //Делает массив случайным
- for (int i(0); i < m; i++)
- arr[i] = new int[n];
- cout << "Случайный массив A: " << endl;
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- arr[i][j] = rand() % 21 - 5; // Массив выводит числа от -5 до 15
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- m = 4; n = 5;
- int** yrr = new int* [m];
- for (int i(0); i < m; i++)
- yrr[i] = new int[n];
- cout << "Случайный массив Y: " << endl;
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- yrr[i][j] = rand() % 21 - 5;
- cout << yrr[i][j] << " ";
- }
- cout << endl;
- }
- cout << endl;
- cout << "Средне геометрическое массива:" << endl;
- int scet, nescet, h;
- scet = 0, nescet = 0, m = 4; n = 5, h = 0;
- //Цикл в котором все положительные числа строк умножаются, считается количество множителей
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (arr[i][j] > 0)
- {
- scet = scet * arr[i][j];
- h++;
- }
- if (yrr[i][j] > 0)
- {
- scet = scet * yrr[i][j];
- h++;
- }
- }
- if (scet > 0)
- {
- scet = pow(scet, 1 / h); //должно считаться средне арефметическое
- }
- cout << scet << endl;
- scet = 0;
- }
- return 0;
- }// То, что я последнее делала позавчера я не сохранила, есть только документ с первыми тремя попытками, так что решила переписать его уже заново и добавить вместо сложения это средне геометрическое, но все равно не получается....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement