#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
void change_Arrays(int** tab1, int** tab2, int m_size)
{
int **temp;
int i,j;
temp=new int *[m_size];
for(i=0;i<m_size;i++)
temp[i]=new int[m_size];
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
temp[i][j]=tab1[i][j];
}
}
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
tab1[i][j]=tab2[i][j];
}
}
for(i=0;i<m_size;i++)
{
for(j=0;j<m_size;j++)
{
tab2[i][j]=temp[i][j];
}
}
for(i=0;i<m_size;i++)
delete [] temp[i];
delete [] temp;
}
int sum_double_Array(int **tab, int m_size)
{
int i,j,sum;
sum=0;
for(i=0;i<m_size;i++)
for(j=0;j<m_size;j++)
sum+=tab[i][j];
return sum;
}
double aver_double_Array(int **tab, int m_size)
{
double aver;
aver=(1.00*sum_double_Array(tab,m_size))/(1.00*m_size);
return aver;
}
int main()
{
srand(time(NULL));
int i,j,k;
int **tab1,**tab2;
int sum1, sum2;
double aver1,aver2;
k=20;
tab1=new int *[k];
tab2=new int *[k];
for(i=0;i<k;i++)
{
tab1[i]=new int[k];
tab2[i]=new int[k];
}
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
tab1[i][j]=rand()%k+1;
tab2[i][j]=rand()%k+1;
}
}
sum1=sum_double_Array(tab1,k);
sum2=sum_double_Array(tab2,k);
aver1=aver_double_Array(tab1,k);
aver2=aver_double_Array(tab2,k);
cout<<"Sum table 1: "<<sum1<<endl;
cout<<"Sum table 2: "<<sum2<<endl;
cout<<"Aver table 1: "<<aver1<<endl;
cout<<"Aver table 2: "<<aver2<<endl;
change_Arrays(tab1,tab2,k);
sum1=sum_double_Array(tab1,k);
sum2=sum_double_Array(tab2,k);
aver1=aver_double_Array(tab1,k);
aver2=aver_double_Array(tab2,k);
cout<<"AFTER CHANGE: \n";
sum1=sum_double_Array(tab1,k);
sum2=sum_double_Array(tab2,k);
aver1=aver_double_Array(tab1,k);
aver2=aver_double_Array(tab2,k);
cout<<"Sum table 1: "<<sum1<<endl;
cout<<"Sum table 2: "<<sum2<<endl;
cout<<"Aver table 1: "<<aver1<<endl;
cout<<"Aver table 2: "<<aver2<<endl;
change_Arrays(tab1,tab2,k);
sum1=sum_double_Array(tab1,k);
sum2=sum_double_Array(tab2,k);
aver1=aver_double_Array(tab1,k);
aver2=aver_double_Array(tab2,k);
for(i=0;i<k;i++)
{
delete [] tab2[i];
delete [] tab1[i];
}
delete [] tab2;
delete [] tab1;
return 0;
}
YOU CAN PAY ME - https://paypal.me/LukaszW77?locale.x=pl_PL