# C语言调用函数实现矩阵自乘-问答-阿里云开发者社区-阿里云

## C语言调用函数实现矩阵自乘

a123456678 2016-03-19 13:58:40 2363

``````#include
//void SelfMul(int A1[][maxSize],int A2[][maxSize],int n)
void SelfMul(int A1[][3],int A2[][3],int n)
{
int s=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
A2[i][j]=0;
for(int k=0;k<n;k++)
A2[i][j]=A2[i][j]+A1[i][k]*A1[k][j];
printf("%d ",A2[i][j]);
if(++s%3==0)printf("\n");
}
}
int main()
{
int A1[][3]={{0,1,0},{0,0,1},{1,1,0}};
int A2[3][3];
// int s=0;
SelfMul(A1[][3],A2[][3],3); //编译问题出错提示所在行
/*
for(int m=0;m<3;m++)
for(int b=0;b<3;b++)
{
printf("%d ",A2[m][b]);
if(++s%3==0)printf("\n");
}
*/
return 0;
}``````

• 游客x4uu57rrcwjuo
2020-03-19 10:48:17

cpp里没有[]这种索引方式吧

0 0
• 一生有你llx
2019-07-17 19:08:04

include

void SelfMul(int (A1)[3],int (A2)[3],int n)
{
int s=0;
for(int i=0;ifor(int j=0;j{
A2i=0;
for(int k=0;kA2i=A2i+A1i*A1k;
printf("%d ",A2i);
if(++s%3==0)printf("n");
}
}
int main()
{
int A1[][3]={{0,1,0},{0,0,1},{1,1,0}};
int A23;

SelfMul(&A1,&A2,3);

return 0;
}

0 0 1
1 1 0
0 1 1

0 0
• nothingfinal
2019-07-17 19:08:04

include

void SelfMul(int (A1)[3],int (A2)[3],int n)
{
int s=0;
for(int i=0;ifor(int j=0;j{
A2i=0;
for(int k=0;kA2i=A2i+A1i*A1k;
printf("%d ",A2i);
if(++s%3==0)printf("n");
}
}
int main()
{
int A1[][3]={{0,1,0},{0,0,1},{1,1,0}};
int A23;

SelfMul(&A1,&A2,3);

return 0;
}

0 0 1
1 1 0
0 1 1

include

void SelfMul(int (A1)[3],int (A2)[3],int n)
{
int s=0;
for(int i=0;ifor(int j=0;j{
A2i=0;
for(int k=0;kA2i=A2i+A1i*A1k;
printf("%d ",A2i);
if(++s%3==0)printf("n");
}
}
int main()
{
int A1[][3]={{0,1,0},{0,0,1},{1,1,0}};
int A23;

SelfMul(&A1,&A2,3);

return 0;
}

0 0 1
1 1 0
0 1 1

0 0
• xumaojun
2019-07-17 19:08:04

# include

void SelfMul(int (A1)[3],int (A2)[3],int n)
{
int s=0;
for(int i=0;ifor(int j=0;j{
A2i=0;
for(int k=0;kA2i=A2i+A1i*A1k;
printf("%d ",A2i);
if(++s%3==0)printf("n");
}
}
int main()
{
int A1[][3]={{0,1,0},{0,0,1},{1,1,0}};
int A23;

SelfMul(&A1,&A2,3);

return 0;
}

0 0 1
1 1 0
0 1 1

0 0
• a123456678
2019-07-17 19:08:04

标准的[]里面应该是有值的
你试试这个编译应该不会出错，但是运行就不知道了

``````enter code here  #include <stdio.h>
void SelfMul(int A1[][3],int A2[][3],int n);
void SelfMul(int A1[][3],int A2[][3],int n)
{
int s=0;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
{
A2[i][j]=0;
for(int k=0; k<n; k++)
A2[i][j]=A2[i][j]+A1[i][k]*A1[k][j];
printf("%d ",A2[i][j]);
if(++s%3==0)printf("\n");
}
}
int main()
{
int A1[][3]= {{0,1,0},{0,0,1},{1,1,0}};
int A2[3][3];
int s = 0;
SelfMul(A1[3][3],A2[3][3],3);
for(int m=0; m<3; m++)
for(int b=0; b<3; b++)
{
printf("%d ",A2[m][b]);
if(++s%3==0)printf("\n");
}

return 0;
}``````
0 0

+ 订阅