Advertisement
themlgyo

28/09/2017

Sep 28th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. Номер строки с максимальным количеством нулей:
  2.  
  3. #include <iostream>
  4. using namespace std;
  5. int main()
  6. {
  7.     setlocale(LC_ALL, "RUSSIAN");
  8.     const int nLine = 4, nColumn = 5;
  9.     int matrix[nLine][nColumn];
  10.     cout << "Введите элементы массива:" << nLine << " на " << nColumn << endl;
  11.     for (auto &arr : matrix)
  12.         for (auto &x : arr) cin >> x;
  13.     int iLine = -1, maxCount = 0;
  14.     for (int i = 0; i < nLine; ++i) {
  15.         int count = 0;
  16.         for (const auto &x : matrix[i]) if (x == 0) ++count;
  17.         if (count > maxCount) { iLine = i; maxCount = count; }
  18.     }
  19.     cout << "Исходный массив:\n";
  20.     for (const auto &arr : matrix) {
  21.         for (const auto &x : arr) cout << "\t" << x;
  22.         cout << endl;
  23.     }
  24.     cout << " " << endl;
  25.     if (iLine == -1) cout << "Нулевых элементов нет: ";
  26.     else cout << "Номер строки: " << iLine;
  27. }
  28.  
  29. ###############################################################################
  30.  
  31. Количество ненулевых элементов в строке и сред арифм.
  32. #include <iostream>
  33. #include <iomanip>
  34. using std::endl;
  35. using std::cout;
  36. using std::cin;
  37.  
  38. void main(){
  39.     setlocale(LC_ALL, "RUSSIAN");
  40.     const int nrow = 2, ncol = 3;
  41.     int a[nrow][ncol];
  42.     int i, j;
  43.     cout << "Введите элементы массива: " << endl;
  44.     for (i = 0; i < nrow; i++)
  45.         for (j = 0; j < ncol; j++) cin >> a[i][j];
  46.  
  47.     for (i = 0; i < nrow; i++){
  48.         for (j = 0; j < ncol; j++) cout << std::setw(4) << a[i][j] << " ";
  49.         cout << endl;
  50.         }
  51.     int n_pos_el;
  52.     float s = 0;
  53.     for (i = 0; i < nrow; i++){
  54.         n_pos_el = 0;
  55.         for (j = 0; j < ncol; j++){
  56.             s += a[i][j];
  57.             if (a[i][j] > 0) n_pos_el++;
  58.         }
  59.         cout << " Строка: " << i << " кол-во: " << n_pos_el << endl;
  60.     }
  61.     s /= nrow*ncol;
  62.     cout << "Среднее арифметическое: " << s << endl;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement