#include <stdio.h> int main(){ int arr[][3]={{1,2,3}, {4,5,6}, {7,8,9}}; printf("before change! "); int i,j,t; for(i=0; i<3; i++ ){ for(j=0; j<3; j++){ printf("%3d",*(*(arr+i)+j)); } printf(" "); } for(i=0;i<3;i++){ for(j=0;j<i;j++){ t=*(*(arr+i)+j); *(*(arr+i)+j)=*(*(arr+j)+i); *(*(arr+j)+i)=t; } } //改变后 printf("after change! "); for(i=0; i<3; i++ ){ for(j=0; j<3; j++){ printf("%3d",*(*(arr+i)+j)); } printf(" "); } return 0; }
结果:
犯了一个小错误,输出换行的时候用的是printf(' '),改成双引号就对了。附上printf() 的用法。
1,printf()函数是格式化输出函数, 一般用于向标准输出设备按规定格式输出信息。
2,printf()函数的调用格式为: printf("<格式化字符串>", <参量表>)。
3,格式输出,它是c语言中产生格式化输出的函数(在 stdio.h 中定义)。用于向终端(显示器、控制台等)输出字符。
格式控制由要输出的文字和数据格式说明组成。要输出的文字除了可以使用字母、数字、空格和一些数字符号以外,
还可以使用一些转义字符表示特殊的含义。
4,作用:在c语言中产生格式化输出的函数(定义在 stdio.h 中),其向终端(显示器、控制台等)输出字符。