求高手编写一个对我来说 超难!!的C语言题目,谢谢啦!!

2024-11-24 23:15:09
推荐回答(1个)
回答1:

n是一个定值? 或者是一个要求输入的值?

#define n 2

void display(int a[n][n])
{
int i,j;
printf("\n");
for(i=0;i {
for(j=0;j {
printf("%d ",a[i][j]);
}
printf("\n");
}
}

void maxIndex(int a[n][n])
{
int i,j,I,J;
I=0;
J=0;
for(i=0;i {
for(j=0;j {
if(a[I][J] {
I=i;
J=j;
}
}
}
printf("max in array: a[%d][%d]=%d\n",I,J,a[I][J]);
}

int product(int a[n][n])
{
int i,p=1;
for(i=0;i {
p*=a[i][i];
}
return p;
}

void trans(int a[n][n])
{
int i,j,t;
for(i=0;i {
for(j=i+1;j {
t=a[i][j];
a[i][j]=a[j][i];
a[j][i]=t;
}
}
}

void add(int a[n][n],int b[n][n],int sum[n][n])
{
int i,j,t;
for(i=0;i {
for(j=0;j {
sum[i][j]=a[i][j]+b[i][j];
}
}
}

void main()
{
int i,j,a[n][n],b[n][n],sum[n][n];
for(i=0;i {
for(j=0;j {
printf("please input a[%d][%d]:\n",i,j);
scanf("%d",&a[i][j]);
}
}

maxIndex(a);

printf("dui jiao xian cheng ji: %d\n", product(a));

display(a);
trans(a);
display(a);

for(i=0;i {
for(j=0;j {
printf("please input b[%d][%d]:\n",i,j);
scanf("%d",&b[i][j]);
}
}
display(b);
add(a,b,sum);
display(sum);

printf("\npress any key to exit:\n");
getch();
}