资源描述:
《C语言第十一章》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、用指向一维数组的指针变量即二维数组的行指针作为函数参数,实现矩阵转置。按如下函数原型编程计算并输出m×n阶矩阵的转置矩阵。其中,m和n的值由用户从键盘输入。已知m和n的值都不超过10。voidTranspose(int(*a)[N],int(*at)[M],intm,intn);voidInputMatrix(int(*a)[N],intm,intn);voidPrintMatrix(int(*at)[M],intn,intm);输入提示信息:"Inputm,n:"输入格式:"%d,%d"输入提示信息:"In
2、put%d*%dmatrix:"输出提示信息和格式:"Thetransposedmatrixis:"输出格式:"%dt"#include#defineM10#defineN10voidTranspose(int(*a)[N],int(*at)[M],intm,intn);voidInputMatrix(int(*a)[N],intm,intn);voidPrintMatrix(int(*at)[M],intn,intm);intmain(){ints[M][N],st[N][M],
3、m,n;printf("Inputm,n:");scanf("%d,%d",&m,&n);InputMatrix(s,m,n);Transpose(s,st,m,n);printf("Thetransposedmatrixis:");PrintMatrix(st,n,m);return0;}voidTranspose(int(*a)[N],int(*at)[M],intm,intn){inti,j;for(i=0;i4、)+j);}}}voidInputMatrix(int(*a)[N],intm,intn){inti,j;printf("Input%d*%dmatrix:",m,n);for(i=0;i5、ntf("");}}从键盘任意输入一个整型表示的月份值,用指针数组编程输出该月份的英文表示,若输入的月份值不在1~12之间,则输出“Illegalmonth”。**输入格式要求:"%d"提示信息:"Inputmonthnumber:"**输出格式要求:"month%dis%s""Illegalmonth","January","February","March","April","May","June","July",August","September","October","November","
6、December"程序运行示例1如下:Inputmonthnumber:5month5isMay程序运行示例2如下:Inputmonthnumber:13Illegalmonth#includeintmain(){intn;staticchar*monthName[]={"Illegalmonth","January","February","March","April","May","June","July",“August","September","October","November
7、","December"};printf("Inputmonthnumber:");scanf("%d",&n);if((n<=12)&&(n>=1))printf("month%dis%s",n,monthName[n]);elseprintf("%s",monthName[0]);return0;}按如下函数原型编程计算并输出n×n阶矩阵的转置矩阵。其中,n由用户从键盘输入。已知n值不超过10。voidTranspose(int*a,intn);voidSwap(int*x,int*y);void
8、InputMatrix(int*a,intn);voidPrintMatrix(int*a,intn);输入提示信息:"Inputn:"输入格式:"%d"输入提示信息:"Input%d*%dmatrix:"输出提示信息:"Thetransposedmatrixis:"输出格式:"%dt"#include#defineN10voidTranspose(int*a,intn)