实现程序,输入一个N*N的矩阵,对角线输出每个元素,大概意思如下:
比如输入4*4的矩阵:
{{0, 1, 2, 3},{4, 5, 6, 7},{8, 9,10,11},{12,13,14,15}}输出为 :
0,1,4,2,5,8,3,6,9,12 …
void main()
{
const int N = 4;
int a[N][N] = {{0,1,2,3},{4,5,6,7},{8,9,10,11},{12,13,14,15}};
int i,j,k;
for(k = 0;k <= 2 * (N - 1); k ++)
{
for(i = 0;i < N;i ++)
{
for(j = 0;j < N;j ++)
{
if(k == i + j)
{
printf("%2d ",a[i][j]); //a[j][i]
}
}
}
}
}