Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <sstream>
- using namespace std;
- int pz, zr, sumz, sumr, minn, maxx, maxx2, minn2,minn3, s, y, i, rnd = 0;
- float b;
- string l;
- int er[4][4], kr[4], kz[4];
- void arrayF() // masiva aizp.
- {
- srand(time(0));
- zr = 0;
- cout << " Ka aizpildit masivu?" << endl;
- do
- {
- cout << "1 = auto, 2 = manual " << endl;
- cin >> l;
- stringstream be(l);
- be >> b;
- if (b == 1)
- {
- cout << " Masiva automatiska aizpildisana " << endl;
- for (y = 0; y < 4; y++)
- {
- for (i = 0; i < 4; i++)
- {
- er[y][i] = rand() % 30 - 20;
- }
- }
- zr = 1;
- }
- if (b == 2)
- {
- cout << " Masiva manuala aizpildisana " << endl;
- for (y = 0; y < 4; y++)
- {
- for (i = 0; i < 4; i++)
- {
- cin >> s;
- er[y][i] = s;
- s = 0;
- }
- }
- zr = 1;
- }
- } while (zr == 0);
- }
- int main()
- {
- arrayF();
- cout << endl;
- system("cls");
- //1
- cout << "\n Masivs 16 ";
- cout << endl
- << endl; pz=0;
- for (y = 0; y < 4; y++)
- {
- for (i = 0; i < 4; i++)
- {
- if (er[y][i] > 0)
- pz = pz + 1;
- cout << "\t" << er[y][i];
- }
- cout << "\n";
- }
- cout << "\n Pozitivo skaitlu daudzums = " << pz << endl;
- cout << endl;
- cout << endl;
- arrayF();
- cout << endl;
- cout << "\n 2. uzd" << endl;
- cin.get();
- system("cls");
- //2
- cout << "\n Masivs 16 ";
- cout << endl;
- for (y = 0; y < 4; y++)
- {
- for (i = 0; i < 4; i++)
- {
- if (i == 1)
- {
- sumz = sumz + er[y][i];
- kr[y] = er[y][i];
- }
- if (i == 3)
- {
- sumr = sumr + er[y][i];
- kz[y] = er[y][i];
- }
- cout << "\t" << er[y][i];
- }
- cout << "\n";
- }
- cout << "\n Pat summa (2) = ";
- for (i = 0; i < 4; i++)
- {
- if (kr[i] < 0 && i == 3)
- cout << "(" << kr[i] << ") = ";
- if (kr[i] > 0 && i == 3)
- cout << kr[i] << " = ";
- if (kr[i] < 0 && i < 3)
- cout << "(" << kr[i] << ") + ";
- if (kr[i] >= 0 && i < 3)
- cout << kr[i] << " + ";
- }
- cout << sumz << endl;
- cout << endl;
- cout << "\n Pat summa (4) = ";
- for (i = 0; i < 4; i++)
- {
- if (kz[i] < 0 && i == 3)
- cout << "(" << kz[i] << ") = ";
- if (kz[i] > 0 && i == 3)
- cout << kz[i] << " = ";
- if (kz[i] < 0 && i < 3)
- cout << "(" << kz[i] << ") + ";
- if (kz[i] >= 0 && i < 3)
- cout << kz[i] << " + ";
- }
- cout << sumr << endl;
- cout << endl;
- cout << endl;
- arrayF();
- cout << endl;
- cin.get();
- system("cls");
- //3
- cout << "\n Masivs 16 " << endl;
- cout << endl;
- for (y = 0; y < 4; y++)
- {
- cout << y + 1 << ")";
- minn3 = er[y][0];
- for (i = 0; i < 4; i++)
- {
- cout << "\t" << er[y][i];
- if (er[y][i] < minn3)
- {
- minn3 = er[y][i];
- }
- }
- cout << "\t Mazakais =" << minn3;
- cout << "\n";
- }
- cout << endl;
- cout << endl;
- arrayF();
- cout << endl;
- pz = 0;
- cin.get();
- system("cls");
- //4
- cout << "\n Masivs 16 " << endl;
- cout << endl;
- for (y = 0; y < 4; y++)
- {
- pz = 0;
- cout << y + 1 << ")";
- for (i = 0; i < 4; i++)
- {
- cout << "\t" << er[y][i];
- if (er[y][i] > 0)
- pz = pz + 1;
- }
- cout << "\n";
- if (pz == 4 && rnd == 0)
- {
- rnd = y + 1;
- }
- }
- cout << "\n Pozitiva linija = " << rnd << endl;
- cout << endl;
- cout << endl;
- arrayF();
- cout << endl;
- cin.get();
- system("cls");
- //5uzd
- cout << "\n Masivs 16 pirms apmainas " << endl;
- cout << endl;
- minn = maxx = er[0][0];
- minn2 = maxx2 = 1;
- for (y = 0; y < 4; y++)
- {
- cout << y + 1 << ")";
- for (i = 0; i < 4; i++)
- {
- cout << "\t" << er[y][i];
- if (er[y][i] < minn)
- {
- minn = er[y][i];
- minn2 = y + 1;
- }
- if (er[y][i] > maxx)
- {
- maxx = er[y][i];
- maxx2 = y + 1;
- }
- }
- cout << "\n";
- }
- cout << "\n Mazakais skaitlis = " << minn << "\t Mazaka skaitla rinda = " << minn2 << endl;
- cout << "\n Lielakais skaits = " << maxx << "\t Lielaka numuru rinda = " << maxx2 << endl;
- for (i = 0; i < 4; i++)
- {
- swap(er[maxx2 - 1][i], er[minn2 - 1][i]);
- }
- cout << "\n Masivs 16 pec mijmainas " << endl;
- cout << endl;
- for (y = 0; y < 4; y++)
- {
- cout << y + 1 << ")";
- for (i = 0; i < 4; i++)
- {
- cout << "\t" << er[y][i];
- }
- cout << "\n";
- }
- cout << endl;
- cin.get();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement