Advertisement
Gromov

Untitled

Dec 15th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <sstream>
  4.  
  5. using namespace std;
  6.  
  7. int  pz, zr, sumz, sumr, minn, maxx, maxx2, minn2,minn3, s, y, i, rnd = 0;
  8. float b;
  9. string l;
  10. int er[4][4], kr[4], kz[4];
  11.  
  12. void arrayF()         // masiva aizp.
  13. {
  14.  srand(time(0));
  15.     zr = 0;
  16.     cout << " Ka aizpildit masivu?" << endl;
  17.     do
  18.     {
  19.         cout << "1 = auto, 2 = manual " << endl;
  20.         cin >> l;
  21.         stringstream be(l);
  22.         be >> b;
  23.         if (b == 1)
  24.         {
  25.             cout << " Masiva automatiska aizpildisana " << endl;
  26.             for (y = 0; y < 4; y++)
  27.             {
  28.                 for (i = 0; i < 4; i++)
  29.                 {
  30.                     er[y][i] = rand() % 30 - 20;
  31.                 }
  32.             }
  33.             zr = 1;
  34.         }
  35.         if (b == 2)
  36.         {
  37.             cout << " Masiva manuala aizpildisana " << endl;
  38.             for (y = 0; y < 4; y++)
  39.             {
  40.                 for (i = 0; i < 4; i++)
  41.                 {
  42.                     cin >> s;
  43.                     er[y][i] = s;
  44.                     s = 0;
  45.                 }
  46.             }
  47.             zr = 1;
  48.         }
  49.     } while (zr == 0);
  50. }
  51.  
  52. int main()
  53. {
  54.     arrayF();
  55.     cout << endl;
  56.  system("cls");
  57.  
  58.            //1
  59.  
  60.     cout << "\n Masivs 16  ";
  61.     cout << endl
  62.     << endl; pz=0;
  63.     for (y = 0; y < 4; y++)
  64.     {
  65.         for (i = 0; i < 4; i++)
  66.         {
  67.             if (er[y][i] > 0)
  68.                 pz = pz + 1;
  69.             cout << "\t" << er[y][i];
  70.         }
  71.         cout << "\n";
  72.     }
  73.     cout << "\n Pozitivo skaitlu daudzums = " << pz << endl;
  74.     cout << endl;
  75.     cout << endl;
  76.     arrayF();
  77.     cout << endl;
  78.     cout << "\n 2. uzd" << endl;
  79. cin.get();
  80.  system("cls");
  81.  
  82.                        //2
  83.  
  84.  
  85.     cout << "\n Masivs 16 ";
  86.     cout << endl;
  87.     for (y = 0; y < 4; y++)
  88.     {
  89.         for (i = 0; i < 4; i++)
  90.         {
  91.             if (i == 1)
  92.             {
  93.                 sumz = sumz + er[y][i];
  94.                 kr[y] = er[y][i];
  95.             }
  96.             if (i == 3)
  97.             {
  98.                 sumr = sumr + er[y][i];
  99.                 kz[y] = er[y][i];
  100.             }
  101.             cout << "\t" << er[y][i];
  102.         }
  103.         cout << "\n";
  104.     }
  105.     cout << "\n Pat summa (2) = ";
  106.     for (i = 0; i < 4; i++)
  107.     {
  108.         if (kr[i] < 0 && i == 3)
  109.             cout << "(" << kr[i] << ") = ";
  110.        
  111.         if (kr[i] > 0 && i == 3)
  112.             cout << kr[i] << " = ";
  113.        
  114.         if (kr[i] < 0 && i < 3)
  115.             cout << "(" << kr[i] << ") + ";
  116.        
  117.         if (kr[i] >= 0 && i < 3)
  118.             cout << kr[i] << " + ";
  119.     }
  120.     cout << sumz << endl;
  121.     cout << endl;
  122.     cout << "\n Pat summa (4) = ";
  123.     for (i = 0; i < 4; i++)
  124.     {
  125.         if (kz[i] < 0 && i == 3)
  126.             cout << "(" << kz[i] << ") = ";
  127.        
  128.         if (kz[i] > 0 && i == 3)
  129.             cout << kz[i] << " = ";
  130.        
  131.         if (kz[i] < 0 && i < 3)
  132.             cout << "(" << kz[i] << ") + ";
  133.        
  134.         if (kz[i] >= 0 && i < 3)
  135.             cout << kz[i] << " + ";
  136.     }
  137.     cout << sumr << endl;
  138.     cout << endl;
  139.     cout << endl;
  140.     arrayF();
  141.     cout << endl;
  142. cin.get();
  143.  system("cls");
  144.  
  145.             //3
  146.    
  147.     cout << "\n Masivs 16 " << endl;
  148.     cout << endl;
  149.     for (y = 0; y < 4; y++)
  150.     {
  151.         cout << y + 1 << ")";
  152.         minn3 = er[y][0];
  153.        
  154.         for (i = 0; i < 4; i++)
  155.         {
  156.             cout << "\t" << er[y][i];
  157.            
  158.             if (er[y][i] < minn3)
  159.             {
  160.                 minn3 = er[y][i];
  161.             }
  162.         }
  163.         cout << "\t Mazakais =" << minn3;
  164.         cout << "\n";
  165.     }
  166.     cout << endl;
  167.     cout << endl;
  168.     arrayF();
  169.     cout << endl;
  170.     pz = 0;
  171. cin.get();
  172.  system("cls");
  173.  
  174.  
  175.              //4
  176.    
  177.     cout << "\n Masivs 16 " << endl;
  178.     cout << endl;
  179.     for (y = 0; y < 4; y++)
  180.     {
  181.         pz = 0;
  182.         cout << y + 1 << ")";
  183.         for (i = 0; i < 4; i++)
  184.         {
  185.             cout << "\t" << er[y][i];
  186.             if (er[y][i] > 0)
  187.                 pz = pz + 1;
  188.         }
  189.         cout << "\n";
  190.         if (pz == 4 && rnd == 0)
  191.         {
  192.             rnd = y + 1;
  193.         }
  194.     }
  195.     cout << "\n Pozitiva linija = " << rnd << endl;
  196.     cout << endl;
  197.  
  198.     cout << endl;
  199.     arrayF();
  200.     cout << endl;
  201. cin.get();
  202.  system("cls");
  203.  
  204.  
  205.     //5uzd
  206.    
  207.     cout << "\n Masivs 16 pirms apmainas " << endl;
  208.    
  209.     cout << endl;
  210.     minn = maxx = er[0][0];
  211.     minn2 = maxx2 = 1;
  212.  
  213.     for (y = 0; y < 4; y++)
  214.     {
  215.         cout << y + 1 << ")";
  216.         for (i = 0; i < 4; i++)
  217.         {
  218.             cout << "\t" << er[y][i];
  219.             if (er[y][i] < minn)
  220.             {
  221.                 minn = er[y][i];
  222.                 minn2 = y + 1;
  223.             }
  224.  
  225.             if (er[y][i] > maxx)
  226.             {
  227.                 maxx = er[y][i];
  228.                 maxx2 = y + 1;
  229.             }
  230.         }
  231.         cout << "\n";
  232.     }
  233.     cout << "\n Mazakais skaitlis =  " << minn << "\t Mazaka skaitla rinda = " << minn2 << endl;
  234.     cout << "\n Lielakais skaits =  " << maxx << "\t Lielaka numuru rinda = " << maxx2 << endl;
  235.     for (i = 0; i < 4; i++)
  236.     {
  237.         swap(er[maxx2 - 1][i], er[minn2 - 1][i]);
  238.     }
  239.     cout << "\n Masivs 16 pec mijmainas " << endl;
  240.     cout << endl;
  241.     for (y = 0; y < 4; y++)
  242.     {
  243.         cout << y + 1 << ")";
  244.         for (i = 0; i < 4; i++)
  245.         {
  246.             cout << "\t" << er[y][i];
  247.         }
  248.         cout << "\n";
  249.     }
  250.    
  251.     cout << endl;
  252.     cin.get();
  253.     system("pause");
  254.     return 0;
  255.    
  256. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement