钱能二维数组的问题
最近在学习钱能那本c++第八章的时候,习题是写个矩阵转秩的小程序,结果发现没能实现,可是从两排星号中间的输出来看,明明已经实现的了啊,各位大虾能不能帮我看看啊。每一条输出都输出了值和对应的地址:
#include <stdio.h>
#include <iostream.h>
#include <math.h>
void main()
{
int k=0;
int Matrix[5][5];
int i,j,itemp;
int * addr;
for(i=0;i <5;i++)
{
for(j=0;j <5;j++)
{
Matrix[i][j]=k++;
cout < <Matrix[i][j] < < "______ " < <&Matrix[i][j] < < " ";
}
cout < <endl;
}
cout < < "************************************************ " < <endl;
addr=Matrix[0];
for(i=0;i <5;i++)
{
for(j=0;j <5;j++)
{
itemp=*(addr+5*i+j);
cout < < "Before: " < < " ";
cout < <*(addr+5*i+j) < < "_____ " < <(addr+5*i+j) < < " " < <*(addr+5*j+i) < < "______ " < <(addr+5*j+i) < < " ";
*(addr+5*i+j)=*(addr+5*j+i);
*(addr+5*j+i)=itemp;
cout < < "after " < < " ";
cout < <*(addr+5*i+j) < < "_____ " < <(addr+5*i+j) < < " " < <*(addr+5*j+i) < < "______ " < <(addr+5*j+i) < <endl;
}
}
cout < < "************************************************ " < <endl;
for(i=0;i <5;i++)
{
for(j=0;j <5;j++)
{
cout < <*(addr+5*i+j) < < "______ " < <(addr+5*i+j) < < " ";
}
cout < <endl;
}
}
[解决办法]
你这个程序,相当于转秩了两遍,当然就和没有转秩时输出一样了,如果想成功,把第一个星号下的代码改为
cout < < "************************************************ " < <endl;
addr=Matrix[0];
for(i=0;i <5;i++)
{
for(j=0;j <=i;j++)//这个要改
{
钱能二维数组的有关问题
钱能二维数组的问题最近在学习钱能那本c++第八章的时候,习题是写个矩阵转秩的小程序,结果发现没能实现,可
