Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. /*
  2. Заданы два массива А(5) и В(5).
  3. Подсчитать в них количество положительных элементов и первым на
  4. печать вывести массив, имеющий наибольшее их количество.*/
  5.  
  6. #include "pch.h"
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     setlocale(LC_ALL, "Russian");
  13.     int kol1 = 0, kol2 = 0;
  14.     int mas1[5];
  15.     int mas2[5];
  16.  
  17.     for (int i = 0; i < 5; i++) {
  18.         cout << "[mas1(" << i + 1 << ")]" << ": " << endl;
  19.         cin >> mas1[i];
  20.         if (mas1[i] > 0)
  21.             {
  22.             kol1 = kol1 + 1;
  23.             }
  24.     }
  25.  
  26.     for (int i = 0; i < 5; i++) {
  27.         cout << "[mas2(" << i + 1 << ")]" << ": " << endl;
  28.         cin >> mas2[i];
  29.         if (mas2[i] > 0)
  30.         {
  31.             kol2 = kol2 + 1;
  32.         }
  33.     }
  34.  
  35.     if (kol1 > kol2)
  36.     {
  37.         cout << "В первом больше положительных:" << endl;
  38.         for (int i = 0; i < 5; ++i) {
  39.             cout << mas1[i] << " " << endl;
  40.         }
  41.     }
  42.    
  43.     if (kol2 > kol1)
  44.     {
  45.         cout << "Во втором больше положительных:" << endl;
  46.         for (int i = 0; i < 5; ++i) {
  47.             cout << mas2[i] << " " << endl;
  48.         }
  49.     }
  50.    
  51.     if (kol2 == kol1)
  52.     {
  53.         cout << "Одинаковое количество положительных:" << endl;
  54.         cout << "Первый массив:" << endl;
  55.         for (int i = 0; i < 5; ++i) {
  56.             cout << mas1[i] << " " << endl;
  57.         }
  58.         cout << "Второй массив:" << endl;
  59.         for (int i = 0; i < 5; ++i) {
  60.             cout << mas2[i] << " " << endl;
  61.         }
  62.     }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement