Advertisement
BuZi

ДЗ№DynamicArray [ADD]

Oct 18th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4.  
  5. using std::cout;
  6. using std::endl;
  7. using std::cin;
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13.     setlocale(LC_ALL, "rus");
  14.  
  15.         int n;
  16.  
  17.     cout << "Кол-во элементов: ";
  18.     cin >> n;
  19.  
  20.     int *a = new int[n];
  21.  
  22.     int pro = 1;
  23.     int kol = 0;
  24.  
  25.     cout << "Введите элементы массивa: ";
  26.  
  27.     for (int i = 0; i < n; i++)
  28.     {
  29.         cin >> a[i];
  30.     }
  31.  
  32.     for (int i = 0; i < n; i++)
  33.     {
  34.         if (a[i] > 30 || a[i] < 3)
  35.         {
  36.             kol++;
  37.             pro*= a[i];
  38.         }
  39.     }
  40.     cout << "pro = " << pro << endl;
  41.     cout << "kol = " << kol << endl;
  42.  
  43.     return 0;
  44. }
  45.  
  46. ______________________________________________________
  47. #include <iostream>
  48.  
  49. using namespace std;
  50.  
  51. int main()
  52. {
  53.     setlocale(LC_ALL, "rus");
  54.  
  55.     int n, m;
  56.     int kol = 0;
  57.  
  58.     cout << "Arr[n][m]" << endl;
  59.     cout << "n= ";
  60.     cin >> n;
  61.     cout << "m= ";
  62.     cin >> m;
  63.    
  64.     int **a = new int *[n];
  65.     for (int i = 0; i < n; i++)
  66.         a[i] = new int [m];
  67.  
  68.     for (int i = 0; i < n; i++)
  69.     {
  70.         for (int j = 0; j < m; j++)
  71.         {
  72.             cout << 1 + j << "-й элемент строки массива: ";
  73.             cin >> a[i][j];
  74.         }
  75.         cout << endl;
  76.     }
  77.    
  78.  
  79.  
  80.     for (int i = 0; i < n; i++)
  81.     {
  82.         for (int j = 0; j < m; j++)
  83.         {
  84.             if (a[i][j] == 1)
  85.             {
  86.                 kol++;
  87.             }
  88.  
  89.         }
  90.     }
  91.     cout << kol << endl;
  92.  
  93.     return 0;
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement