1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
using namespace std;
const int SIZE = 51;
void print( double A[SIZE][SIZE], int rows, int cols )
{
for ( int i = 0; i < rows; i++ )
{
for ( int j = 0; j < cols; j++ ) cout << A[i][j] << '\t';
cout << '\n';
}
}
void insertedAverage( int &N, int &M, double A[SIZE][SIZE], int k )
{
for ( int j = 0; j < M; j++ )
{
double value = 0;
for ( int i = 0; i < N; i++ ) value += A[i][j];
value /= N;
for ( int i = N; i > k; i-- ) A[i][j] = A[i-1][j];
A[k][j] = value;
}
N++;
}
int main()
{
int N = 2, M = 2;
int k = 1;
double A[SIZE][SIZE] = { { 1, 1 }, { 2, 2 } };
print( A, N, M ); cout << '\n';
insertedAverage( N, M, A, k );
print( A, N, M );
}
|