Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int arrayIndexSize, arraySize, randRangeFrom, randRangeTo, multiply;
- bool isSecondPositive, isFirst;
- char v(0);
- cout << "Enter array\'s first index\' value: ";
- cin >> arrayIndexSize;
- cout << "Enter array\'s second index\' value: ";
- cin >> arraySize;
- if (arrayIndexSize < 1 || arraySize < 1) {
- cout << "\n\nBoth values must be posivive integers.\n\n";
- return 0;
- }
- int** arr = new int* [arrayIndexSize];
- for (int i = 0; i < arrayIndexSize; i++)
- {
- arr[i] = new int[arraySize];
- }
- cout << "\n\nHow would You like to fill in array, (M)anually or (A)utomatically? \n:";
- cin >> v;
- if (v == 'M') {
- for (int i = 0; i < arrayIndexSize; i++)
- {
- cout << "Entering row " << i + 1 << ".\n\n";
- for (int j = 0; j < arraySize; j++)
- {
- cout << "Enter element " << j + 1 << ": ";
- cin >> arr[i][j];
- }
- cout << endl;
- }
- }
- else if (v == 'A') {
- cout << "Enter initial range value: ";
- cin >> randRangeFrom;
- cout << "Enter end range value: ";
- cin >> randRangeTo;
- cout << endl;
- srand(time(NULL));
- for (int i = 0; i < arrayIndexSize; i++)
- {
- for (int j = 0; j < arraySize; j++)
- {
- arr[i][j] = rand() % (randRangeTo - randRangeFrom + 1) + randRangeFrom;
- }
- }
- }
- else {
- cout << "\nI expected \"M\" or \"A\".\n\n";
- return 0;
- }
- cout << "Your array:\n\n";
- // Aprēķināt pozitīvu elementu reizinājumu tajās masīva rindās, kurās ir vismaz divi pozitīvie elementi.
- for (int i = 0; i < arrayIndexSize; i++) {
- multiply = 0;
- isSecondPositive = false;
- isFirst = false;
- for (int j = 0; j < arraySize; j++)
- {
- if (!isFirst && arr[i][j] >= 0)
- {
- cout << setw(5) << arr[i][j];
- multiply = arr[i][j];
- isFirst = true;
- }
- else if (isFirst && arr[i][j] >= 0)
- {
- cout << setw(5) << arr[i][j];
- multiply *= arr[i][j];
- isSecondPositive = true;
- }
- else
- {
- cout << setw(5) << arr[i][j];
- }
- }
- cout << " | ";
- if (isSecondPositive)
- {
- cout << multiply;
- }
- else if (!isFirst)
- {
- cout << "no positives";
- }
- else
- {
- cout << "no second positive";
- }
- cout << endl;
- }
- for (int i = 0; i < arrayIndexSize; i++)
- {
- delete[] arr[i];
- }
- delete[] arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement