错误:无效操作数到二进制+ (拥有浮点'和float **

发布于 2025-01-29 04:16:47 字数 399 浏览 2 评论 0原文

    void clc_moy_mdl(int n, int m,float *mt[3][30])
{
    float s;
    int i,j;
    s=0;

    remplire_matrice(n,m,tab,mt);
    for(j=1;i<=n;j++)
    {
        for(i=1;i<=(m-1);i++)
        {
            s =s+ mt[i][j];
            printf("%f",s);
        }
        mt[i][j]= s /(m);
    }
}

这是我编写程序的程序 我在第12行中有错误 错误:无效的操作数到二进制 +(具有“ float”和“ float **”) 我该如何解决?

    void clc_moy_mdl(int n, int m,float *mt[3][30])
{
    float s;
    int i,j;
    s=0;

    remplire_matrice(n,m,tab,mt);
    for(j=1;i<=n;j++)
    {
        for(i=1;i<=(m-1);i++)
        {
            s =s+ mt[i][j];
            printf("%f",s);
        }
        mt[i][j]= s /(m);
    }
}

this is a procedure from a program that I write it
I have an error in line 12
error:invalid operands to binary + (have 'float' and 'float **')
How can I solve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隐诗 2025-02-05 04:16:47

参数mt被声明为具有数组类型float *[3] [30]

void clc_moy_mdl(int n, int m,float *mt[3][30])

因此,表达式mt [i] [j] has类型float *和在这些语句中

s =s+ mt[i][j];

,并且

mt[i][j]= s /(m);

使用指针和浮点数错误地操作。

取而代之的是,要么您必须写入

s =s + *mt[i][j];

*mt[i][j]= s /(m);

声明该功能,要么

void clc_moy_mdl(int n, int m,float mt[3][30])

像注意该数组索引从0开始。因此,

for(j=1;i<=n;j++)

您程序中这样的循环似乎可以产生不确定的行为。你应该写

for(j=0;i<n;j++)

The parameter mt is declared as having the array type float *[3][30]

void clc_moy_mdl(int n, int m,float *mt[3][30])

Thus the expression mt[i][j] has the type float * and in these statements

s =s+ mt[i][j];

and

mt[i][j]= s /(m);

there are used incorrectly operations with a pointer and a float.

Either instead you have to write

s =s + *mt[i][j];

and

*mt[i][j]= s /(m);

or to declare the function like

void clc_moy_mdl(int n, int m,float mt[3][30])

Pay attention to that array indices start from 0. So it seems the for loops like this

for(j=1;i<=n;j++)

in your program can produce undefined behavior. You should write

for(j=0;i<n;j++)
久而酒知 2025-02-05 04:16:47

float *mt [3] [30]mt定义为指针的2D阵列float

删除*

您还可以使用传递的大小来声明此参数。


void clc_moy_mdl(size_t n, size_t m,float mt[n][m])
{
    float s = 0.0f;
    size_t i,j;

    for(j = 0; i < n; j++)
    {
        for(i = 0; i < m; i++)
        {
            s += mt[i][j];
            printf("%f", s);
        }
        mt[i][j]= s / m;
    }
}

请记住,索引是从0开始的,然后使用正确的类型(size_t

float *mt[3][30] defines mt as 2D array of pointers to float.

Remove the *

You can also use the passed sizes to declare this parameter.


void clc_moy_mdl(size_t n, size_t m,float mt[n][m])
{
    float s = 0.0f;
    size_t i,j;

    for(j = 0; i < n; j++)
    {
        for(i = 0; i < m; i++)
        {
            s += mt[i][j];
            printf("%f", s);
        }
        mt[i][j]= s / m;
    }
}

Remember that indexes start from 0 and use the correct types for sizes (size_t)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文