Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Номер строки с максимальным количеством нулей:
- #include <iostream>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUSSIAN");
- const int nLine = 4, nColumn = 5;
- int matrix[nLine][nColumn];
- cout << "Введите элементы массива:" << nLine << " на " << nColumn << endl;
- for (auto &arr : matrix)
- for (auto &x : arr) cin >> x;
- int iLine = -1, maxCount = 0;
- for (int i = 0; i < nLine; ++i) {
- int count = 0;
- for (const auto &x : matrix[i]) if (x == 0) ++count;
- if (count > maxCount) { iLine = i; maxCount = count; }
- }
- cout << "Исходный массив:\n";
- for (const auto &arr : matrix) {
- for (const auto &x : arr) cout << "\t" << x;
- cout << endl;
- }
- cout << " " << endl;
- if (iLine == -1) cout << "Нулевых элементов нет: ";
- else cout << "Номер строки: " << iLine;
- }
- ###############################################################################
- Количество ненулевых элементов в строке и сред арифм.
- #include <iostream>
- #include <iomanip>
- using std::endl;
- using std::cout;
- using std::cin;
- void main(){
- setlocale(LC_ALL, "RUSSIAN");
- const int nrow = 2, ncol = 3;
- int a[nrow][ncol];
- int i, j;
- cout << "Введите элементы массива: " << endl;
- for (i = 0; i < nrow; i++)
- for (j = 0; j < ncol; j++) cin >> a[i][j];
- for (i = 0; i < nrow; i++){
- for (j = 0; j < ncol; j++) cout << std::setw(4) << a[i][j] << " ";
- cout << endl;
- }
- int n_pos_el;
- float s = 0;
- for (i = 0; i < nrow; i++){
- n_pos_el = 0;
- for (j = 0; j < ncol; j++){
- s += a[i][j];
- if (a[i][j] > 0) n_pos_el++;
- }
- cout << " Строка: " << i << " кол-во: " << n_pos_el << endl;
- }
- s /= nrow*ncol;
- cout << "Среднее арифметическое: " << s << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement