[英]Printing out a 2d array in a specific format in C
So basically when i print my array it looks like this: 因此,基本上,当我打印数组时,它看起来像这样:
P00 P01 P02
P10 P11 P12
P20 P21 P22
I want it to look like this: 我希望它看起来像这样:
M[0][0] M[0][1] M[0][2]
M[0][0] P00 P01 P02
M[1][0] P10 P11 P12
M[2][0] P20 P21 P22
My code: 我的代码:
for (z=0; z<N; z++){
for (c=0; c<N;c++){
printf("\t%p", &M[z][c]);
}
printf("\n");
}
Note that Pxx is the pointer address 请注意,Pxx是指针地址
above outer loop : 在外循环上方:
printf("\t\tM[0][0]\tM[0][1]\tM[0][2]\n");
and then just below outer loop : 然后在外循环下面:
printf("M[%d][0]\t",i);
Look like this: 看起来像这样:
printf("\t\t");
for (z=0; z<N; z++)
printf("\tM[0][%d]",z);
printf("\n");
for ( z=0; z<N; z++){
printf("M[%d][0]\t",z);
for(c=0; c<N; c++){
printf("\t%p",&M[z][c]);
}
printf("\n");
}
Maybe something like this: 也许是这样的:
for(i=0;i<N;i++){
printf("\tM[0][%d]",i);
}
printf("\n");
for (z=0; z<N; z++){
printf("M[%d][0]",z);
for (c=0; c<N;c++){
printf(" %p\t", &M[z][c]);
}
printf("\n");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.