Дана квадратная таблица a[1:n,1:n]. Найти номер строки, содержащей наибольшее число нулей- C++(Си)

#include <iostream>

using namespace std;

int main()
{
    setlocale (LC_ALL, "Russian");
    int n, i, j;
    std::cout<<"Введите размерность:\nn = ", std::cin>>n; 
    int **matr = new int*[n];
    for(i = 0; i < n; ++i)
        matr[i] = new int[n];
    system("cls");
    std::cout<<"Введите матрицу размерностью "<<n<<'x'<<n<<":\n";
    for (i = 0; i < n; ++i)
        for(j = 0; j < n; ++j)
            std::cin>>matr[i][j];
    std::cout<<"Введенная матрица:\n";
    for(i = 0; i < n; ++i, std::cout<<'\n')
        for(j = 0; j < n; ++j)
            std::cout<<matr[i][j]<<' ';
    int *mas = new int[n]; 
    for(i = 0; i < n; ++i)
    {
        mas[i] = 0;
        for(j = 0; j < n; ++j)
            if(matr[i][j] == 0)
                mas[i]++;
    }
    int max = mas[0], index(0);
    for(i = 1; i < n; ++i)
        if(mas[i] > max)
        {
            max = mas[i];
            index = i;
        }
    std::cout<<"Номер строки, содержащей наибольшее число нулей: "<<index<<'\n';
    system("pause");
    return 0;
}

One Thought to “Дана квадратная таблица a[1:n,1:n]. Найти номер строки, содержащей наибольшее число нулей- C++(Си)”

  1. Im very pleased to discover this web site. I want to to thank you for your time due to this wonderful read!! I definitely loved every bit of it and i also have you book marked to see new information in your blog.

Leave a Comment