Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <sstream>
- using namespace std;
- int s, r, i, poz, p, sum1, sum2, miinR, rind = 0, miin, maax, maxR, minR;
- float a;
- string b, si;
- int x[4][4], f[4], h[4];
- void arrayF() // masiva aizpilde
- {
- srand(time(0));
- p = 0;
- cout << "How to fill array auto or manually" << endl;
- do
- {
- cout << "1 = auto, 2 = manually" << endl;
- cin >> b;
- stringstream be(b);
- be >> a;
- if (a == 1)
- {
- cout << "Array auto fill" << endl;
- for (r = 0; r < 4; r++)
- {
- for (i = 0; i < 4; i++)
- {
- x[r][i] = rand() % 30 - 20;
- }
- }
- p = 1;
- }
- if (a == 2)
- {
- cout << "Array manual fill" << endl;
- for (r = 0; r < 4; r++)
- {
- for (i = 0; i < 4; i++)
- {
- cin >> s;
- x[r][i] = s;
- s = 0;
- }
- }
- p = 1;
- }
- } while (p == 0);
- }
- int main()
- {
- arrayF();
- system("cls");
- cout << "\n1uzd" << endl; //1uzd
- cout << "\nArray of 16 ";
- cout << endl
- << endl;
- for (r = 0; r < 4; r++)
- {
- for (i = 0; i < 4; i++)
- {
- if (x[r][i] > 0)
- poz = poz + 1;
- cout << "\t" << x[r][i];
- }
- cout << "\n\n";
- }
- cout << "\nPozitivo skaitlu daudzums = " << poz << endl;
- cout << endl;
- system("pause");
- system("cls");
- arrayF();
- system("cls");
- cout << "\n2uzd" << endl; //2uzd
- cout << "\nArray of 16 ";
- cout << endl
- << endl;
- for (r = 0; r < 4; r++)
- {
- for (i = 0; i < 4; i++)
- {
- if (i == 1)
- {
- sum1 = sum1 + x[r][i];
- f[r] = x[r][i];
- }
- if (i == 3)
- {
- sum2 = sum2 + x[r][i];
- h[r] = x[r][i];
- }
- cout << "\t" << x[r][i];
- }
- cout << "\n\n";
- }
- cout << "\n Even sum (2) = ";
- for (i = 0; i < 4; i++)
- {
- if (f[i] < 0 && i == 3)
- cout << "(" << f[i] << ") = ";
- if (f[i] > 0 && i == 3)
- cout << f[i] << " = ";
- if (f[i] < 0 && i < 3)
- cout << "(" << f[i] << ") + ";
- if (f[i] >= 0 && i < 3)
- cout << f[i] << " + ";
- }
- cout << sum1 << endl;
- cout << endl;
- cout << "\n Even sum (4) = ";
- for (i = 0; i < 4; i++)
- {
- if (h[i] < 0 && i == 3)
- cout << "(" << h[i] << ") = ";
- if (h[i] > 0 && i == 3)
- cout << h[i] << " = ";
- if (h[i] < 0 && i < 3)
- cout << "(" << h[i] << ") + ";
- if (h[i] >= 0 && i < 3)
- cout << h[i] << " + ";
- }
- cout << sum2 << endl;
- cout << endl;
- system("pause");
- system("cls");
- arrayF();
- system("cls");
- cout << "\n3uzd" << endl; //3uzd
- cout << "\nArray of 16 " << endl;
- cout << endl;
- for (r = 0; r < 4; r++)
- {
- cout << r + 1 << ")";
- miinR = x[r][0];
- for (i = 0; i < 4; i++)
- {
- cout << "\t" << x[r][i];
- if (x[r][i] < miinR)
- {
- miinR = x[r][i];
- }
- }
- cout << "\tSmallest =" << miinR;
- cout << "\n\n";
- }
- cout << endl;
- system("pause");
- system("cls");
- arrayF();
- system("cls");
- poz = 0;
- cout << "\n4uzd" << endl; //4uzd
- cout << "\nArray of 16 " << endl;
- cout << endl;
- for (r = 0; r < 4; r++)
- {
- poz = 0;
- cout << r + 1 << ")";
- for (i = 0; i < 4; i++)
- {
- cout << "\t" << x[r][i];
- if (x[r][i] > 0)
- poz = poz + 1;
- }
- cout << "\n\n";
- if (poz == 4 && rind == 0)
- {
- rind = r + 1;
- }
- }
- cout << "\nPositive line = " << rind << endl;
- cout << endl;
- system("pause");
- system("cls");
- arrayF();
- system("cls");
- cout << "\n5uzd" << endl; //5uzd
- cout << "\nArray of 16 before swap " << endl;
- cout << endl;
- miin = maax = x[0][0];
- minR = maxR = 1;
- for (r = 0; r < 4; r++)
- {
- cout << r + 1 << ")";
- for (i = 0; i < 4; i++)
- {
- cout << "\t" << x[r][i];
- if (x[r][i] < miin)
- {
- miin = x[r][i];
- minR = r + 1;
- }
- if (x[r][i] > maax)
- {
- maax = x[r][i];
- maxR = r + 1;
- }
- }
- cout << "\n\n";
- }
- cout << "\nSmallest number = " << miin << "\tSmallest number line = " << minR << endl;
- cout << "\nBiggest number = " << maax << "\tBiggest number line = " << maxR << endl;
- for (i = 0; i < 4; i++)
- {
- swap(x[maxR - 1][i], x[minR - 1][i]);
- }
- cout << "\nArray of 16 after swap " << endl;
- cout << endl;
- for (r = 0; r < 4; r++)
- {
- cout << r + 1 << ")";
- for (i = 0; i < 4; i++)
- {
- cout << "\t" << x[r][i];
- }
- cout << "\n\n";
- }
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement