7.左边第一张图片-------
#include <stdio.h>
#include <stdlib.h>
main()
{
int i,j,a[5][5];
void su(int a[][5]);
void sum(int a[][5]);
void tr(int a[][5]);
printf("The two-dimensional array is:\n");
for(i=0;i<5;i++,printf("\n"))for(j=0;j<5;j++)scanf("%d",&a[i][j]);//输入
printf("Transposition of the two-dimensional array is:\n");
su(a);
sum(a);
tr(a);
system("pause");return 0;
}
void su(int a[5][5])//求对角线和并输出
{
int i,c=0,d=0;
for(i=0;i<5;i++)c+=a[i][i];
for(i=0;i<5;i++)d+=a[i][4-i];
printf("sum(/)=%d\tsum(\\)=%d\n",d,c);
}
void sum(int a[5][5])//求每行元素总和并输出
{
int i,j,b[5];
for(i=0;i<5;i++)for(b[i]=0,j=0;j<5;j++)b[i]+=a[i][j];
for(i=0;i<5;i++)printf("sum(a[%d][])=%d\n",i,b[i]);
}
void tr(int a[5][5])//数组转置并输出
{
int i,j,b[5][5];
for(i=0;i<5;i++)for(j=0;j<5;j++)b[i][j]=a[i][j];
for(i=0;i<5;i++)for(j=0;j<5;j++)a[i][j]=b[j][i];
for(i=0;i<5;i++,printf("\n"))for(j=0;j<5;j++)printf("%d\t",a[i][j]);
}
7.右边第二张图片-------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main()
{
char a[10][20]={"chinese666",
"englishasd",
"japan..ssss",
"england",
"britainddddd",
"United Kingdomjhgj.",
"Americadasdae",
"the Americas ",
"South Americ",
"South Americe"};
void p(char a[][20]);
p(a);
system("pause");return 0;
}
void p(char a[10][20])
{
int i,maxstr=0,secstr=1;char t[20];
for(i=1;i<10;i++)maxstr=(strlen(a[maxstr])>strlen(a[i]))?maxstr:i;
for(i=2;i<10;i++)if(i!=maxstr)
secstr=(strlen(a[secstr])>strlen(a[i]))?secstr:i;
printf("maxstr=%s\n",a[maxstr]);
printf("secstr=%s\n",a[secstr]);
}
有不懂吗