2.2

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.2 kB
0
Indexable
Never
#include <iostream>
using namespace std;
void Nhap(int**,int);
void Xuat(int**,int);
int Cau5(int **,int,int);
int main()
{
    int n;
    do
    {
        cout<<" (2 <= n <= 5) n = ";
        cin>>n;
    }while(n < 2 || n > 5);

    int **a = new int*[n];
    for(int i =0; i < n; ++i)
    {
        a[i] = new int[n];
    }
    Nhap(a,n);
    Xuat(a,n);

    int k;
    do
    {
        cout<<" (0 <= n <= "<<n - 1 <<") k = ";
        cin>>k;
    }while(k < 0 || k > n - 1);

    cout<<"So luong so duong tren cot "<<k<<" la : "<<Cau5(a,n,k);
    return 0;
}
void Nhap(int **a,int n)
{
    for(int i = 0; i < n ; ++i)
    {
        for(int j = 0;  j < n; ++j)
        {
            cout<<"a["<<i<<"]["<<j<<"] = ";
            cin>>a[i][j];
        }
    }
}
void Xuat(int **a,int n)
{
    cout<<"A[][]:\n";
    for(int i = 0; i < n ; ++i)
    {
        for(int j = 0;  j < n; ++j)
        {
            cout<<a[i][j]<<"\t";
        }
        cout<<endl;
    }
}
int Cau5(int **a,int n,int k)
{

    int result = 0;
    for(int i= 0 ; i < n; ++i)
    {
        if(a[i][k] > 0) result++;
    }
    return result;
}