在C+&#x2B中以可变大小的矩阵输入输入。
我正在尝试检查C ++中矩阵A的正交性。 为此,我正在宣布行数和列数的“最大值”值,然后我试图获取矩阵的行数和列数,从而声明它。 来获取矩阵元素的输入。
#include <stdio.h>
#define MAX 10
int arows,acolumns; /*line 4*/
void input_matix(float (*arr)[MAX],int arows,int acolumns)
{/*asks user for input of individual elements*/}
void transpose(float (*T)[MAX],float (*A)[MAX],int arows,int acolumns)
{/*gets me the transpose*/}
void product(float (*A)[MAX],float (*T)[MAX],float (*P)[MAX])
{/*multiplies two matrices and places the product in P matrix*/}
int orthogonal_array(float (*arr)[MAX]){/*returns 1 if arr is ortho*/}
int main()
{
//int arows,acolumns;
printf("Enter the no. of rows and columns of matrix A: \n");
scanf("%d %d",&arows,&acolumns);
float A[arows][acolumns];
if (arows != acolumns)
{
printf("Not a orthogonal matrix.\n");
}
else
{
input_matix(A,arows,acolumns);
orthogonal_array(A);
}
}
之后
cannot convert 'float (*)[acolumns] to float (*)[10]'
,我试图
extern int arows,acolumns;
通过使用指针到矩阵的行等上的指针 最大] float arr [] [Acolumns]
同样的是功能中的其他参数,但随后我得到了错误,
"expression must have a constant value"
"array bound is not a integer constant before "]" token */
请建议我做什么,以使这些功能正常工作
I am trying to check the orthogonality of a matrix A in c++.
For that I am declaring a "MAX" value of number of rows and columns, then I am trying to get the number of rows and columns for the matrix, hence declaring it.
After that I am trying to get the input for the matrix elements by using pointer to the rows of the matrix and so on ..
#include <stdio.h>
#define MAX 10
int arows,acolumns; /*line 4*/
void input_matix(float (*arr)[MAX],int arows,int acolumns)
{/*asks user for input of individual elements*/}
void transpose(float (*T)[MAX],float (*A)[MAX],int arows,int acolumns)
{/*gets me the transpose*/}
void product(float (*A)[MAX],float (*T)[MAX],float (*P)[MAX])
{/*multiplies two matrices and places the product in P matrix*/}
int orthogonal_array(float (*arr)[MAX]){/*returns 1 if arr is ortho*/}
int main()
{
//int arows,acolumns;
printf("Enter the no. of rows and columns of matrix A: \n");
scanf("%d %d",&arows,&acolumns);
float A[arows][acolumns];
if (arows != acolumns)
{
printf("Not a orthogonal matrix.\n");
}
else
{
input_matix(A,arows,acolumns);
orthogonal_array(A);
}
}
When compiling it I am getting the error
cannot convert 'float (*)[acolumns] to float (*)[10]'
I have tried replacing line 4 with
extern int arows,acolumns;
and replacing float (*arr)[MAX] byfloat arr[][acolumns]
similarly other parameters in the functions but then I get the error that
"expression must have a constant value"
"array bound is not a integer constant before "]" token */
Please suggest me what should I do, so as to make these functions work properly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

根本原因是不允许使用C ++ VLA(Varibale Length Arrays)。到目前为止,它不是语言C ++的一部分。
float a [Arwows] [Acolumns];
是无效的C ++代码。
在C中您可以做,但不能在C ++中
The root cause is that in C++ VLA (Varibale Length Arrays) are not allowed. It is not a part of the language C++ so far.
float A[arows][acolumns];
is invalid C++ code.
In C you can do, but not in C++