Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341619
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:05:54

#include
#include
#include
using namespace std;
 int m=2;
 int n=3;
void ShowMatrix(double **);
double MaxtrixAvg(double **);
void Sum(double **,double **,double **);
double MatrixAvg(double **);
void LackMemory();

int main()
{
int i,j;
//¶¯Ì¬ÄÚ´æ·ÖÅäpMa
set_new_handler(LackMemory);
double **pMa= new double *[m];
for( i=0;i pMa[i]=new double[n];


for( i=0;i for( j=0;j pMa[i][j]=(i*i+2.0*j)/2.0;

//¶¯Ì¬ÄÚ´æ·ÖÅäpMb
double **pMb= new double *[m];
pMb[0]= new double [m*n];
for( i=1;i pMb[i]=pMb[i-1]+n;
for( i=0;i for( j=0;j pMb[i][j]=double(i+j)/2.0;

//¶¯Ì¬ÄÚ´æ·ÖÅäpMc
double **pMc= new double *[m];
pMc[0]= new double [m*n];
for( i=1;i pMc[i]=pMc[i-1]+n;
//for(int i=0;i //for(int j=0;j
//ÏÔʾpMaºÍpMb
cout<<"Êý×épMaÊÇ£º"< ShowMatrix(pMa);
cout<<"Êý×épMbÊÇ£º"< ShowMatrix(pMb);
//ÇópMc
Sum(pMa,pMb,pMc);
cout<<"Êý×épMa + pMb ÊÇ£º"< ShowMatrix(pMc);
//ÇópMaµÄƽ¾ùÖµ
cout<<"Êý×épMaµÄƽ¾ùÖµÊÇ£º"<
//»ØÊÕpMa
for(i=0;i delete [] pMa[i];
delete [] pMa;
//»ØÊÕpMb
delete [] pMb[0];
delete [] pMb;
//»ØÊÕpMc
delete [] pMc[0];
delete [] pMc;

return 0;
}
void ShowMatrix(double **M)
{
for(int i=0;i {
for(int j=0;j cout< cout< }
cout< return;
}
double MatrixAvg(double **M)
{
double Sum = 0;
for (int i=0;i for(int j=0;j Sum+=M[i][j];
return Sum/double(m*n);
}
void Sum(double **X,double **Y,double **Z)
{
for (int i=0;i for(int j=0;j Z[i][j]=X[i][j]+Y[i][j];
return;
}
void LackMemory()
{
cerr<<"ÄÚ´æ²»×㣡\n";
abort();
}





--------------------next---------------------

阅读(1069) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~