1、用函数编程实现两个数组中对应该元素值的交换(数组的长度定义成5)。Outputarraya:12345Outputarrayb:678910#includestdio.h#includestdlib.hvoidExchange(inta[],intb[]);intmain(){inti,a[5],b[5];for(i=0;i5;i++)scanf(%5d,&a[i]);for(i=0;i5;i++)scanf(%5d,&b[i]);Exchange(a[i],b[i]);for(i=0;i5;i++)printf(%5d,a[i]);printf(\n);for(i=0;i5;i++)printf(%5d,b[i]);printf(\n);return0;}voidExchange(inta[],intb[]){inttemp,i;for(i=0;i5;i++){temp=a[i];a[i]=b[i];b[i]=temp;}}2、从键盘任意输入10个整数,将其中最大数与最小数的位置对换,然后输出对换后的10个数。[提示:用一维数组存放这10个数]输入要求:%d,输入的数据用空格作分隔符。详见输入样例。输出要求:%d,输出的数据用空格作分隔符。详见输出样例。输入输出样例:输入:21043567819输出:21435678109输入:16234597810输出:10623459781#includestdio.h#includestdlib.hvoidExchange(inta[],intn);intFindMax(ints[],intn);intFindMin(ints[],intn);intmain(){inti,a[10];for(i=0;i10;i++){scanf(%d,&a[i]);}Exchange(a,10);for(i=0;i10;i++){printf(%d,a[i]);}printf(\n);return0;}voidExchange(inta[],intn){intMax,Min,temp;Max=FindMax(a,n);Min=FindMin(a,n);temp=a[Max];a[Max]=a[Min];a[Min]=temp;}intFindMax(ints[],intn){intMax=0,M=s[0],i;for(i=1;in;i++){if(s[i]M){M=s[i];Max=i;}}returnMax;}intFindMin(ints[],intn){intMin=0,m=s[0],i;for(i=1;in;i++){if(s[i]m){m=s[i];Min=i;}}returnMin;}3、用二维数组存放杨辉三角形中的数据,这些数据的特点是:第1列和对角线上的元素值都为1。其余的左下角元素值为:a[i][j]=a[i-1][j-1]+a[i-1][j],注意i和j的变化范围。输入要求:无输出要求:%d#includestdio.h#includestdlib.h#defineN20voidCYH(inta[][N],intn);voidPYH(inta[][N],intn);intmain(){inta[N][N]={0};intn=10;CYH(a,n);PYH(a,n);return0;}voidCYH(inta[][N],intn){inti,j;for(i=0;in;i++){for(j=0;j=i;j++){if(j==0||i==j)a[i][j]=1;elsea[i][j]=a[i-1][j-1]+a[i-1][j];}}}voidPYH(inta[][N],intn){inti,j;for(i=0;in;i++){for(j=0;j=i;j++){printf(%d,a[i][j]);}printf(\n);}}4、从键盘输入一个日期(year-month-day),计算并输出该日期是该年的第几天。请按以下给定的函数原型编程:intCalcDays(intyear,intmonth,intday);返回值:返回的是日期(year-month-day)对应的那天是该年的第几天;若输入的数据有任意一个不满足条件,返回值是-1。#includestdio.h#includestdlib.hintCalcDays(intyear,intmonth,intday);intdayTab[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};intmain(){intyear,month,day,YD;scanf(%d-%d-%d,&year,&month,&day);if(year=0&&month=0&&month=12&&day=0&&day=31){YD=CalcDays(year,month,day);printf(%d\n,YD);}else{printf(-1\n);}return0;}intCalcDays(intyear,intmonth,intday){inti,s;s=((year%4==0)&&(year%100!=0))||(year%400==0);for(i=1;imonth;i++){day=day+dayTab[s][i];}returnday;}5、问题描述:由键盘输入一个5X5阶矩阵,判断该矩阵是否是魔方矩阵。魔方矩阵的定义:每一行、每一列、每一对角线上的元素之和都是相等的。#includestdio.hintmain(){inta[5][5],s[5],t[5];inti,j,k,l,h,n,m;for(i=0;i=4;i++){scanf(%d%d%d%d%d,&a[i][0]&a[i][1],&a[i][2],&a[i][3],&a[i][4]);}for(k=0;k=4;k++){s[k]=0;for(j=0;j=4;j++){s[k]=s[k]+a[k][j];}}for(l=0;l=4;l++){t[l]=0;for(h=0;h=4;h++){t[l]=t[l]+a[l][h];}}m=a[0][0]+a[1][1]+a[2][2]+a[3][3]+a[4][4];n=a[0][4]+a[1][3]+a[2][2]+a[3][1]+a[4][0];if(s[0]==s[1]&&s[1]==s[2]&&s[2]==s[3]&&s[3]==s[4]&&s[4]==t[0]&&t[0]==t[1]&&t[1]==t[2]&&t[2]==t[3]&&t[3]==t[4]&&t[4]==m&&m==n)printf(Itisamagicsquare!);elseprintf(Itisnotamagicsquare!);return0;}6、按如下函数原形编程计算并输出求m*n阶矩阵的转置矩阵。期中m和n的值由用户从键盘输入。已知m和n的值都不超过10。求转置矩阵函数原形:voidTranspose(inta[][N],intm,intn);要求:在主函数中输入m*n数组元素的值,调用函数Transpose()求转置矩阵,输出转置矩阵.友情提示:注意行下标i=0和列下标j=0及ij时的处理!!!#includestdio.hvoidTranspose(inta[10][10],intm,intn);intmain(){inta[10][10];intm,n,i,j;printf(Inputm,n:);scanf(%d,%d,&m,&n);printf(Input%d*%dmatrix:\n,m,n);for(i=0;im;i++)for(j=0;jn;j++)scanf(%d,&a[i][j]);Transpose(a,m,n);printf(Thetransposedmatrixis:\n);for(i=0;in;i++){for(j=0;jm;j++)printf(%4d,a[i][j]);printf(\n);}return0;}voidTranspose(inta[10][10],intm,intn){inttmp,i,j;intM;if(mn)M=m;elseM=n;for(i=0;iM;i++)for(j=i;jM;j++){tmp=a[i][j];a[i][j]=a[j][i];a[j][i]=tmp;}}7、分别按如下函数原形编程计算并输出求m*n阶矩阵的转置矩阵。期中m和n的值由用户从键盘输入。已知m和n的值都不超过10。输入函数原形:voidInputMatrix(inta[][N],intm,intn);求转置矩阵函数原形:voidTranspose(inta[][N],intat[][M],intm,intn);输出函数原形:voidPrintMatrix(intat[][M],intn,intm);#includestdio.h#defineN10#defineM10voidTranspose(inta[][N],intat[][M],intm,intn);voidInputMatrix(inta[][N],intm,intn);voidPrintMatrix(intat[][M],intn,intm);intmain(){inta[M][N],at[N][M],m,n;printf(Inputm,n:);scanf(%d,%d,&m,&n);printf(Input%d*%dmatrix:\n,m,n);InputMatrix(a,m,n);Transpose(a,at,m,n);printf(Thetransposedmatrixis:\n);PrintMatrix(at,n,m);return0;}voidInputMatrix(inta[][N],intm,intn){inti,j;for(j=0;jm;j++){for(i=0;in;i++){scanf(%d,&a[j][i]);}}}voidTranspose(inta[][N],intat[][M],intm,intn){inti,j;for(j=0;jm;j++){for(i=0;in;i++){at[i][j]=a[j][i];}}}voidPrintMatrix(intat[][M],intn,intm){inti,j;for(i=0;im;i++){for(j=0;jn;j++){printf(%8d,at[i][j]);if(j==n-1)putchar(10);}}}8、参考例8.6程序中的函数ReadScor()和Average(),输入某班同学某门课成绩(最多不超过40人),当输入为负值时,表示输入结束,用函数编程统计成绩高于平均分(包括等于平均分)的学生人数。函数intGetAboveAver(intscore[],intn)#includestdio.hintReadScore(intscore[]);intAverage(intscore[],intn);intGetAboveAver(intscore[],intn);intmain(){intscore[40],avescore,n,aboveave;n=ReadScore(score);printf(Totalstudentsare%d\n,n);avescore=Average(score,n);aboveave=GetAboveAver(score,n);printf(Averagescoreis%d\n,avescore);printf(Studentsofaboveaverageis%d,aboveave);return0;}intReadScore(intscore[]){inti=-1;do{i++;pr