2.6

 avatar
TalonEzio
c_cpp
2 years ago
1.2 kB
5
Indexable
Never
#include <iostream>
using namespace std;
void Nhap(int**,int,int&);
int CheoChinh(int **,int);
void Xuat(int **a,int n,bool Even = false)
{

    for(int i = 0; i < n ; ++i)
    {
        for(int j = 0;  j < n; ++j)
        {
            if(Even)
            {
                if(a[i][j] % 2 == 0)cout<<a[i][j]<<"\t";
                else cout<<"x"<<"\t";
            }
            else
            {
                cout<<a[i][j]<<"\t";
            }
        }
        cout<<endl;
    }
}

int main()
{
    int n,Sum = 0;
    cout<<"n = ";
    cin>>n;

    int **a = new int*[n];
    for(int i =0; i < n; ++i)
    {
        a[i] = new int[n];
    }
    Nhap(a,n,Sum);
    cout<<"A[][]:\n";
    Xuat(a,n);
    cout<<"Cau 4 :\n";
    Xuat(a,n,true);
    cout<<"Cau 5: "<<CheoChinh(a,n);
    delete[] a;

}
void Nhap(int **a,int n,int&Sum)
{
    for(int i = 0; i < n ; ++i)
    {
        for(int j = 0;  j < n; ++j)
        {
            cout<<"a["<<i<<"]["<<j<<"] = ";
            cin>>a[i][j];
            Sum+=a[i][j];
        }
    }
}
int CheoChinh(int **a,int n)
{
    int Sum = 0;
    for(int i = 0; i < n ; ++i)
    {
        Sum += a[i][i];
    }
    return Sum;
}