2.3

 avatar
TalonEzio
c_cpp
2 years ago
1.3 kB
5
Indexable
Never
#include <iostream>
using namespace std;
void Nhap(double **,int,int,double&);
void Xuat(double **,int,int);
double TichHangK(double**,int,int,int);
int main()
{
    int n, m;
    cout << "m = "; cin >> m;
    cout << " n = "; cin >> n;
    double avg = 0;
    double** a = new double* [m];
    for (int i = 0; i < m; ++i)
    {
        a[i] = new double[n];
    }
    Nhap(a,m,n,avg);
    Xuat(a,m,n);
    cout<<"Trung binh cong cac phan tu : "<<avg/(m * n)<<endl;

    int k;
    do
    {
        cout<<"(0 < k <= "<<m<<") k = ";
        cin>>k;
    }while(k <= 0 || k > m);
    k--;
    cout<<TichHangK(a,m,n,k);
    delete[] a;
}
void Nhap(double **a,int m,int n,double &avg)
{
    for (int i = 0; i < m; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            cout<<"a["<<i<<"]["<<j<<"] = ";
            cin>>a[i][j];
            avg += a[i][j];
        }
    }
}
void Xuat(double **a,int m, int n)
{
    for (int i = 0; i < m; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            cout<<a[i][j]<<"\t";
        }
        cout << endl;
    }
}
double TichHangK(double **a,int m,int n,int k)
{

    double result = 1;
    for(int i = 0; i < n;++i)
    {
        result *= a[k][i];
    }
    return result;
}